[eluser]smilie[/eluser]
Hi,
First of all - I know this question has been asked before - and I know that most common answer is to look in user guide (extending classess) and Phil Sturgeon's guide to base classess.
However, I still do not grasp the concept of it.
Let me put what I would like to achieve and if someone would be kind enough to point me to right direction.
Idea / problem:
I have a sidebar on the website which is visible on every page;
In that sidebar I want to place some statistics.
One way of doing it is to add to every function call to the model and pass it when loading view.
What I would like is to do that only once (somewhere?) and paste it to the view.
So, I believe there are 2 options:
- to create a generally available variable $stats which can be called from any function?
- to call a view in another controller (which is always loaded?).
Oke, I got so far (not working by the way):
Code:
MY_Controller:
class MY_Controller extends Controller
{
function __construct()
{
parent::Controller();
$this->load->model('stats_model');
$this->data['stats'] = $this->stats_model->getStats();
}
}
In all other controllers (function) which generate views:
Code:
class Something extends Controller
{
function Something()
{
parent::Controller();
}
function whatever()
{
# Load pages
$page['content'] = $this->load->view('content/stock_results',$data,TRUE);
$page['header'] = $this->load->view('common/header','',TRUE);
# This is where sidebar is beeing called, so I would like to pass results from above in here
$page['sidebar'] = $this->load->view('common/sidebar',$this->data['stats'],TRUE);
$page['footer'] = $this->load->view('common/footer','',TRUE);
$this->load->view('home',$page)
}
}
However, this does not work
And I would hate to have to copy & paste xx times same model load and stats function :'(
Please help! :-)
Cheers,
Smilie