Passing more than one array to View |
[eluser]wizzer[/eluser]
Model Code: function _getAllUsers() Controller Code: function index() As I understand it, in order for me to pass more than one array to the view, I have to join them together? I have a $stats array that needs to get passed too which is not shown here. My main question is, how do i display this in view, nothing seems to work. Once it does display, what is the best way to pass another array into this view?
[eluser]sl3dg3hamm3r[/eluser]
Like this: Code: $data = array( You can now access your data in the view like this: Code: echo "User-count: " & count($userList) & "<br />"; P.s.: Nice sample application, where you could learn from: bambooinvoice
[eluser]LuckyFella73[/eluser]
Hi Wizzer, what you can do is: Code: <?php
[eluser]darkhouse[/eluser]
LuckyFella73, the only issue with your solution is that you didn't declare $data before you started setting its values. Most servers won't squawk about it, but it will technically throw a notice. Easily fixed by just adding a $data = array(); beforehand. However, I prefer sl3dg3hamm3r's method as it keeps it all in one step really.
[eluser]LuckyFella73[/eluser]
Hi Darkhouse, I found so many code examples in the CI user guide where $data was not declared - that's why I thought $data is declared as an array by CI automaticly. Thanks for the hint.
[eluser]wiredesignz[/eluser]
[quote author="darkhouse" date="1249098573"]... you didn't declare $data before you started setting its values. Most servers won't squawk about it, but it will technically throw a notice. Easily fixed by just adding a $data = array(); beforehand...[/quote] That is not actually correct, PHP being loosely typed does not require that you declare a data type for a variable before using it. If it were true then the CI config and database settings arrays should trigger errors.
[eluser]darkhouse[/eluser]
You're right, it's not a requirement, but some servers will throw an error (unless you've turned errors off) if you don't declare it first. I guess loose programming is more of a pet peeve of mine than anything. |
Welcome Guest, Not a member yet? Register Sign In |