Welcome Guest, Not a member yet? Register   Sign In
Share session data among controllers?
#1

[eluser]drshields[/eluser]
I am wonder what the easiest way to implement "global" session variables that can be set and retrieved from any controller. It seems that in CI, different controllers are treated as entirely different sessions.

If someone could help me out or point me to a previous thread on this topic, I would appreciate it. I've spent some time researching the forum but I have not seen this topic answered directly.

Thanks!
#2

[eluser]gtech[/eluser]
The whole point of the session variable is that it is global between requests (and controllers)

Code:
$newdata = array(
      'userID'  => $query['UserID'],
      'siteadmin'  => $query['SiteAdminBool'],
      'customerID'  => $query['CustomerID'],
      'logged_in' => TRUE);

      $this->session->set_userdata($newdata);

and then you can retrieve it like

Code:
$customerid = $this->session->userdata('customerID');

Just make sure session is in autoloaded in config/autoload.php




Theme © iAndrew 2016 - Forum software by © MyBB