[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
class Welcome extends Controller{
function __construct()
{
parent::Controller();
}
function index()
{
//Load models that process data relevant to this page
$this->load->model('Snipets');
$this->load->model('Quick_links');
// 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);
}
}
?>
Container_View:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<?php $this->load->view('modules/meta');?>
</head>
<body>
<?php $this->load->view('modules/header_view');?>
<?=$content;?>
<?php $this->load->view('modules/footer_view');?>
</body>
</html>