![]() |
Model Error - 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: Model Error (/showthread.php?tid=21475) |
Model Error - El Forum - 08-11-2009 [eluser]georgerobbo[/eluser] I have a model which pulls content from a MySQL database. When I use the query in my controller it works fine, however I am having difficulties in the model. The error being returned is: Quote:A PHP Error was encountered This is my code: Code: <?php Code: <?php Code: <div id="content"> Model Error - El Forum - 08-11-2009 [eluser]OES[/eluser] You are not returning anything from the get_sidecont model. instead of Code: foreach($query->result_array() as $row) do Code: return $query->result_array() Model Error - El Forum - 08-11-2009 [eluser]Johan André[/eluser] I usually do it like this: Code: // The model Code: // The view Model Error - El Forum - 08-11-2009 [eluser]georgerobbo[/eluser] [quote author="OES" date="1250005005"]You are not returning anything from the get_sidecont model. instead of Code: foreach($query->result_array() as $row) do Code: return $query->result_array() I don't understand why the model doesn't return anything. When I have the query in my controller it works perfectly? Model Error - El Forum - 08-11-2009 [eluser]Johan André[/eluser] When you use the code in your controller it populates the $data-array and sends it to the view. Remember that the $data-array in the model is not the same as the $data-array in the controller. The array is a property of the class refeering to it. The model methods that are used to fetch model-data to the controller needs to return something (ie end the method with return $something ![]() Model Error - El Forum - 08-11-2009 [eluser]georgerobbo[/eluser] [quote author="OES" date="1250005005"]You are not returning anything from the get_sidecont model. instead of Code: foreach($query->result_array() as $row) do Code: return $query->result_array() Such a more efficient way of doing it. Thank you very much. |