Welcome Guest, Not a member yet? Register   Sign In
session undefined in library class but works in model and view classes
#1

[eluser]iamzvonko[/eluser]
Hello,

I'm new to CodeIgniter so please bear with me if this is a basic question. I have read the session section in User Guide and searched the forum but I haven't been able to find out why my code doesn't work.

I'm saving an array into session in a view class like this:
Code:
$this->session->set_userdata('resource_ids',$resource_ids);

Then I'm retrieving the array in a model class like this:
Code:
$resource_ids = $this->session->userdata('resource_ids');

That works as expected. The problem is when I try to retrieve the array from a library class like this (which is EXACTLY the same way I do it in the model class):
Code:
$resource_ids = $this->session->userdata('resource_ids');

This results in this error
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Trip_Lib::$session
Filename: libraries/Trip_Lib.php
Line Number: 74

I have confirmed that the application/config/autoload.php file is autoloading session. I've also tried switching to use flashdata (I'm enhancing somebody else's code) instead of userdata since rest of app code uses flashdata. Same result with flashdata.

Any idea why I am getting this kind of behavior? Thanks in advance for any help.

David





Theme © iAndrew 2016 - Forum software by © MyBB