Welcome Guest, Not a member yet? Register   Sign In
Best way to do a query for the header view
#1

[eluser]Kemik[/eluser]
Hello,

Usually I only pass a variable to the header for the page title but what's the best way to do a query on every page?

E.g. header -> query for nav links
body -> normal controller
footer -> no queries required

I don't want to put the same query in every controller. Should it go in the constructor? What about if it's required site wide and not just one set of controllers?

Thanks.
#2

[eluser]Seppo[/eluser]
Have you consider using a hook?
#3

[eluser]Kemik[/eluser]
I've heard hooks are pretty nasty. I could put them in my extended controller I suppose then pass the variable straight to the view using $this->CI->load->vars();
#4

[eluser]esra[/eluser]
If the header is a view fragment, you could create a dedicated helper for the view fragment. You need to create an instance of the CI super object in the helper in order to query a database.




Theme © iAndrew 2016 - Forum software by © MyBB