CodeIgniter Forums
Best Practice - Should I load a view for content or process the data in the controller - 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: Best Practice - Should I load a view for content or process the data in the controller (/showthread.php?tid=21238)



Best Practice - Should I load a view for content or process the data in the controller - El Forum - 08-04-2009

[eluser]deco10[/eluser]
On the left side of my site there is a menu. The content of this menu changes depending on the page but typically there is 5 of the 10 possible items displayed (so some pages have links on the menu that are on other pages). Currently I load the view into the "leftpane" and run a switch statement to determine what content gets printed in the menu.

I'm making some changes and I'm wondering if I should control this content in the controller or if I'm in the right to do it a separate view file and load it. I realize its not a huge deal either way, I'm just looking for what would be the proper MVC method.

In my leftpane_view I have all the links at the top loaded into an assoc. array so I can change them easily.

What do you think?


Thanks for input! Smile


Best Practice - Should I load a view for content or process the data in the controller - El Forum - 08-04-2009

[eluser]Phil Sturgeon[/eluser]
If you do it in the controller you'd end up doing it every time. I would be tempted to create a plugin, or extend the Controller class (search MY_Controller) to give you a method of adding PHP to every pageload.