![]() |
Where should I put menu generation code? - 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: Where should I put menu generation code? (/showthread.php?tid=2710) |
Where should I put menu generation code? - El Forum - 08-20-2007 [eluser]tmcw[/eluser] Okay, so working on le CMS... in my public controllers, for each page generated, I've been putting a bit of logic for fetching items from a Page_model, sorting those into a tree, and putting that on a page. I've got it to the point that I at least have that logic in a function within each controller, so I can call it like $data['menu'] = $this->menu('Page_model') and so on. My question is whether there's a better way to do this... as a helper, plugin, etc? I've been running into the problem that helpers seem to exist outside of the CI object system, so I can't call in a model. Plugins, I think, can, but the manual tells me that they usually have only one associated function. I don't know why. Any suggestions? It isn't a killer problem, but I figure it's fairly common and I'd like to build this thing the best way I can. Thanks Where should I put menu generation code? - El Forum - 08-20-2007 [eluser]tmcw[/eluser] -sorry, posted a follow-up but it turned out to be wrong. Where should I put menu generation code? - El Forum - 08-21-2007 [eluser]obiron2[/eluser] personally, I would put the logic that generates the menu data into a model and the code that generates the menu HTML into a view. you will need to call the menu model in the controller to pass the data to the view. This way, if you change the way that the menu data is stored (e.g. in a database rather than as an array) you don't have to change everything. Where should I put menu generation code? - El Forum - 08-21-2007 [eluser]Michael Wales[/eluser] I agree with obiron - create a model to handle all of your dynamically generated content areas that are global throughout the site (header, navigation, footer, whatever). Call it from the controller (or setup a hook to do it across every controller), and push it out to the view. Where should I put menu generation code? - El Forum - 09-04-2007 [eluser]Phil Sturgeon[/eluser] [quote author="tmcw" date="1187672092"]I've been running into the problem that helpers seem to exist outside of the CI object system, so I can't call in a model. Plugins, I think, can, but the manual tells me that they usually have only one associated function. I don't know why.[/quote] Don't forget you can grab a CI instance from any PHP file which is loaded in the same instance. Code: // PHP 4 |