How to pre-load MySQL data that is used in all pages

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:
class Welcome extends Controller{
    function __construct()
    function index()
        //Load models that process data relevant to this page

        // Load site-wide data that appears on every page

        $data['weather_data'] = $this->Weather->get_weather();
        $data['header_data'] = $this->Header->get_header();
        //we load the view partial as a string that will be passed to the container
        $content_data['view_content'] = '';        
        $data['content'] = $this->load->view('content/welcome_view', $content_data, TRUE);

        //set other data that will be used in the container
        $data['page_title'] = ' Welcome Page';
        //show the container
        $this->load->view('container_view', $data);

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
&lt;html &gt;
&lt;?php $this->load->view('modules/meta');?&gt;
&lt;?php $this->load->view('modules/header_view');?&gt;
&lt;?php $this->load->view('modules/footer_view');?&gt;

You can extend base controller and write the data to it's property ($this->some_data). Or you can use a hook.

example of this particular hook anybody? would this be a post_controller hook?

Hi samota, and welcome to the CI forums.

You almost definitely want to look at [url=""]extending the core controller[/url] and putting these calls into there.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.