CodeIgniter Forums
Loading some data from database for all views in an application - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Loading some data from database for all views in an application (/thread-23230.html)



Loading some data from database for all views in an application - El Forum - 10-04-2009

[eluser]Nameless One[/eluser]
I'm building a website which will have a navigation bar with some items "hardcoded" in the view and some links to static pages that will be defined in the database. Since the navigation bar will be displayed on every page, I need those few database rows in every view so that I could insert them as items in the navigation ul element.

Is there any way to do this without fetching those rows in every controller action?


Loading some data from database for all views in an application - El Forum - 10-04-2009

[eluser]InsiteFX[/eluser]
Yes.

Create a MY_Controller in application/libraries then add your code to that and extend that controller in all of your other controllers.

You can fnd the information for this in the users guide.

Enjoy
InsiteFX


Loading some data from database for all views in an application - El Forum - 10-05-2009

[eluser]Nameless One[/eluser]
That's for the suggestion. I've already come to the same conclusion myself. Wish there was some more elegant way in CI, like a support for HMVC for example.


Loading some data from database for all views in an application - El Forum - 10-05-2009

[eluser]Flemming[/eluser]
HMVC

:-)

it's very easy to set it up!