![]() |
Return Query Object vs Returning Data? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Return Query Object vs Returning Data? (/showthread.php?tid=32107) |
Return Query Object vs Returning Data? - El Forum - 07-13-2010 [eluser]JasonS[/eluser] Hi, Is there some definitive best practice for this? Lets take this simple example. Controller: Code: <?php From here you have 2 options. I usually return the query object like this. Model: Code: <?php You would then have the view. Code: <?php if ($p->num_rows == 0): ?> That is one option. The main benefit of this is how little coding you need to do. Its like 3 lines in your model. The other option is create an array. So, instead of returning the query object you would loop through it and return an array. The main benefit of this second option is that you can pre-process your data. The view is about the same. The difference being that you are interacting with an array instead of an object. Which method do you use and why? OR do you use something else? |