CodeIgniter Forums

Full Version: Loading some data from database for all views in an application
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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?

El Forum

[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

El Forum

[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.

El Forum

[eluser]Flemming[/eluser]
HMVC

:-)

it's very easy to set it up!