Passing a data array from model to controller and then finally to view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Passing a data array from model to controller and then finally to view (/showthread.php?tid=53620) |
Passing a data array from model to controller and then finally to view - El Forum - 07-31-2012 [eluser]Unknown[/eluser] Pretty basic stuff and probably have been asked a thousand times, but can't seem to find a simple answer about this. This is an example of what I'm trying to do : controller Code: $this->load->model('model_name', '', TRUE); model Code: function getAllSomethings() Code: foreach ($something as $row) Obviously does not work. How exactly do you send a data array and then echo everything out. Passing a data array from model to controller and then finally to view - El Forum - 07-31-2012 [eluser]mrh[/eluser] Ok I'm new too so this may have errors. In my model: Code: // Define values to send back So that is in the model. In the controller: Code: // Get admin portal data Finally in the view. In this case I'm specifically populating the array in the model return so that I can use it in a drop down list on a form: Code: <div id="portalblockinfo"> But I could have easily done a php for to access the data in the array Code: <?php for($i=0; $i<count($appData); $i++) { ?> I did $appData[$i][1] to get the projectName from the array. See the query above. Obviously just echoing the array contents will result in everything being on the same line. So you could add a <br> after each echo. The basic difference between my code and yours is that in my model I create the array as a separate element of the $data passed to the view. Passing a data array from model to controller and then finally to view - El Forum - 07-31-2012 [eluser]Aken[/eluser] You need to return the result array in your model. Your code now is only returning the value of the "something" column in the first row of the result set. |