Proper way to send database query from Model to Controller to the 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: Proper way to send database query from Model to Controller to the View (/showthread.php?tid=7974) |
Proper way to send database query from Model to Controller to the View - El Forum - 04-29-2008 [eluser]Jonathan McGaha[/eluser] Ok I already posted once about just trying to get a basic database query working. The replies helped me construct one from the controller. I then used Derek Allard's video to help me construct from the model to the controller and then having an echo in the view to display the results. However, I'm trying to understand the "proper" way of using my active record statements in the model, to then calling that model in the controller. Then I want to be able to work with the array in the view because that's where it makes the most sense for me to work with it. Derek had his query results laid out in html in his model but that doesnt seem right to me. I'd rather in my view layout the foreach statement because it seems that my html layout should be in the view. If I am wrong in my thinking please let me know, because I want to code the proper way from the very beginning. Model: Code: <?php class Scriptures extends Model { Controller: Code: <?php class Bible extends Controller { View: I would assume the foreach goes in the view but please confirm this for me. Proper way to send database query from Model to Controller to the View - El Forum - 04-29-2008 [eluser]Tom Glover[/eluser] The foreach would go in the view other wise you would be sending only the last of its creation to the view. Proper way to send database query from Model to Controller to the View - El Forum - 04-29-2008 [eluser]Jonathan McGaha[/eluser] Is my controller right to send that data into the view? Proper way to send database query from Model to Controller to the View - El Forum - 04-29-2008 [eluser]Tom Glover[/eluser] [quote author="Jaxbulls" date="1209518993"]Is my controller right to send that data into the view?[/quote] Yes, just assign anything to the $data array. then call the array key in the view to load it. for example controller: Code: $data[s1] = "some text"; View file: Code: <? Proper way to send database query from Model to Controller to the View - El Forum - 04-29-2008 [eluser]Taff[/eluser] Code: <?php class Bible extends Controller { Now I could be wrong but I think that should be Code: $data['book_results'] = $this->Scriptures->getVerse(); I like using the optional second parameter when loading my model so for example: Code: <?php class Bible extends Controller { That should get your data array into your bibleview Good luck! Taff Proper way to send database query from Model to Controller to the View - El Forum - 04-29-2008 [eluser]Jonathan McGaha[/eluser] OK thanks you guys helped me a great deal. I checked one more thing in the User Guide to get the foreach right and now I have exactly what I was looking for. Thanks a ton! |