![]() |
Using Parser helper to list data from db - 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: Using Parser helper to list data from db (/showthread.php?tid=11158) |
Using Parser helper to list data from db - El Forum - 08-28-2008 [eluser]alijanah[/eluser] Hi to All, This is my first post actually. I just want to verify my coding methods to list data from db (in the model) and passing it to the view via the standard codeigniter parser helper. If anybody have any better ways, I would be more than grateful if you can share them with me. Thanks in advance. Controller (test.php) - Basically a simple controller to call my model and assign it to the $query variable and them passing it to the view. Code: <?php My Model (test_model.php) - nothing spectacular here, just a simple call but returning the results with the result_array() function instead of result() function. Code: <?php My View (test_view_parser.php) - self explanatory Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" Is this the proper way of doing things or is there any other better ways ?. Thanks. Using Parser helper to list data from db - El Forum - 08-28-2008 [eluser]sophistry[/eluser] Welcome to CI... and very nice first post. This looks ideal - very clean code - and exactly the way CI is set up to help you organize. The only suggestion I have (and I had to look hard for something to criticize) is to pick a good variable naming style: you should rename $query in your controller to $result_array or something like that so that it helps you remember that your model returns an array rather than the actual CI query object. Very minor point, but it will help you keep all your "ducks in a row" as you expand your code. Using Parser helper to list data from db - El Forum - 08-28-2008 [eluser]alijanah[/eluser] Thanks for your comment sophistry. Yes I agree, that's an oversight on my part not renaming the $query return value to something like $country_list_array. So it looks like I'm on a right track here as far as using the template parser is concerned. |