CodeIgniter Forums
Extending controller to fetch common data... but not 100% of the time. - 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: Extending controller to fetch common data... but not 100% of the time. (/showthread.php?tid=29371)



Extending controller to fetch common data... but not 100% of the time. - El Forum - 04-07-2010

[eluser]BilliamTheSecond[/eluser]
I've extended my controller to handle queries used for things like header navigation.

However, right now I'm running queries on pages that never load a view (ex: self-submitting form pages that redirect on success).

How should I deal with automatically fetching data almost all of the time? I only need to run this query if a view is going to be loaded, and specifically, only if the header is loaded.

Really, my header doesn't need to be dynamic right now, and could just be cached, so this is more of a general question.


Extending controller to fetch common data... but not 100% of the time. - El Forum - 04-08-2010

[eluser]n0xie[/eluser]
The way I usually do it, is call a render() function at the end of each function. This builds the template (header/footer/menu) based on which class is loaded and injects some data into it. In this case if you have a self submitting form, just don't call the render function. I don't like auto-loading a lot of stuff from the base_controller because it will slow your page down, since it will ALWAYS load them, even if you don't need them.


Extending controller to fetch common data... but not 100% of the time. - El Forum - 04-08-2010

[eluser]Phil Sturgeon[/eluser]
Different base controllers?