[eluser]KeyStroke[/eluser]
Hi,
I'm looking for the best way to share common data between a controller's methods. Things like:
1. Logged in state
2. The user id of the person logged in (if any)
3. Date variable
and so on. These are used in almost every method in my application.
So far I've been doing something like this:
Code:
function page_name()
{
// get the value of common variables through the returned array
$view_data = $this->_init_common_data();
/*
function code goes here
*/
$this->load->view('view_name', $view_data);
}
function _init_common_data()
{
$data['logged_in'] = $this->session->userdata('logged_in');
$data['username'] = $this->session->userdata('username');
// whatever else here
return $data; // returns an array
}
But this isn't readable nor very practical since I have to call that function with every method I create.
Any suggestions?