CodeIgniter Forums
Main Controller and then 1 controller for subsequent pages. - 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: Main Controller and then 1 controller for subsequent pages. (/showthread.php?tid=12518)



Main Controller and then 1 controller for subsequent pages. - El Forum - 10-22-2008

[eluser]dalebotha[/eluser]
Hi

I have main controller and the page in the site has it's own controller. How would I have a common function which renders the navigation for the site in one place instedad of having it in each model for each page?

Is this a good starting point of or could somebody recommend another approach?

I'm a relative necomer so just a just a point in the right direction would be cool!


Thanks, Dale


Main Controller and then 1 controller for subsequent pages. - El Forum - 10-22-2008

[eluser]Randy Casburn[/eluser]
There are a couple of ways to do things. With simple sites, that's most of us, most of us use a single controller as a base controller (I call mine 'core') and we use a PHP include() statement in each of our other controller files. The base controllers deals with all the common things that appear on each of our pages while the individual controllers deal with the specifics of the page.

If your structure is more complex that this you should look into Modular Extentions (HMVC) or something similar.

Make sense?

Randy


Main Controller and then 1 controller for subsequent pages. - El Forum - 10-22-2008

[eluser]drewbee[/eluser]
In addition to Randy's suggestions, one other option is to extend the default controller. Then all following controllers inherit this extension. The extended main controlller can be used to do exactly this. By Default, I automatically extend this controller in any new app I set up just for sake of knowing if something has a 'need-all' function or data, it will be their.


Main Controller and then 1 controller for subsequent pages. - El Forum - 10-22-2008

[eluser]Randy Casburn[/eluser]
I think we essentially just said exactly the same thing in two different ways.


Main Controller and then 1 controller for subsequent pages. - El Forum - 10-22-2008

[eluser]drewbee[/eluser]
Agreed - save the fact that your method you can include on an as-needed basis.


Edit: Well, actually you can extend just the normal CI controller if you do not want to include the extended feature.


The real question is, do you feel like doing an include and initiating the controller or extending the controller and remembering that you need to extend that particular controller to use it.

Final Answer: To each his own! Smile