How to pre-load MySQL data that is used in all pages - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: How to pre-load MySQL data that is used in all pages (/showthread.php?tid=17733) |
How to pre-load MySQL data that is used in all pages - El Forum - 04-14-2009 [eluser]Ki[/eluser] I have searched for this answer everywhere: I am using a template approach with CI, where each controller loads a compiler template that loads views for static Header, Static Footer and displays Dynamic Content. Dynamic content is passed as variable from controller. Question: If I am using data from 3 MySql tables that is used everywhere - in header that appears on every page as well as in most dynamic content, how can I pre-load it? Caching aside, should I create a hook or a model, and then how can I make $data['query'] = $this->$db->get('TableName') run every time any page is open (or a header is open or better yet, run it as part of initialization procedure for the whole site)? I want to avoid pasting $data['query'] = $this->$db->get('TableName') in EVERY controller. Now I have it in a model, but still I have to call the function that contains $data['query'] = $this->$db->get('TableName') in a model on EVERY controller, which is also something I want to do once for the whole site. Controler Example: Code: <?php Container_View: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> How to pre-load MySQL data that is used in all pages - El Forum - 04-14-2009 [eluser]Choo[/eluser] You can extend base controller and write the data to it's property ($this->some_data). Or you can use a hook. How to pre-load MySQL data that is used in all pages - El Forum - 04-14-2009 [eluser]Ki[/eluser] example of this particular hook anybody? would this be a post_controller hook? How to pre-load MySQL data that is used in all pages - El Forum - 04-14-2009 [eluser]jedd[/eluser] Hi samota, and welcome to the CI forums. You almost definitely want to look at [url="http://ellislab.com/forums/viewthread/109698/"]extending the core controller[/url] and putting these calls into there. Jedd. |