Welcome Guest, Not a member yet? Register   Sign In
How do I share data between my Controller's methods?
#8

[eluser]onejaguar[/eluser]
Although it probably isn't as "clean" as setting a global variable for your class, I get tired of writing $this-> all the time so I often just pass the variable as a reference; e.g.:

Code:
function page_name()
{
   $view_data = array();
   $this->_init_common_data($view_data);

   $this->load->view('view_name', $view_data);
}

   // the & before the variable means this is a reference to the
   // original variable, not a copy.
function _init_common_data(&$data)
{
   $data['logged_in'] = $this->session->userdata('logged_in');
   $data['username'] = $this->session->userdata('username');
}


Messages In This Thread
How do I share data between my Controller's methods? - by El Forum - 05-28-2008, 05:47 AM
How do I share data between my Controller's methods? - by El Forum - 05-28-2008, 05:54 AM
How do I share data between my Controller's methods? - by El Forum - 05-28-2008, 06:04 AM
How do I share data between my Controller's methods? - by El Forum - 05-28-2008, 06:09 AM
How do I share data between my Controller's methods? - by El Forum - 05-28-2008, 06:16 AM
How do I share data between my Controller's methods? - by El Forum - 05-28-2008, 07:48 AM
How do I share data between my Controller's methods? - by El Forum - 05-28-2008, 08:08 AM
How do I share data between my Controller's methods? - by El Forum - 05-28-2008, 10:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB