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

[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?


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