CodeIgniter Forums

Full Version: Accessing Session in a custom helper file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
I am trying to access the session object in a custom helper file. But an error is thrown when calling

$this->session

Is there another way to access it?

THanks,
Randy

El Forum

[eluser]JamieBarton[/eluser]
HI,

You'll need to get an instance of the Code Igniter object to do that.

You can make a variable called $CI in your contruct method, like this:
Code:
$CI =& get_instance();

Then to get the session you would then replace $this, with $CI, such as:
Code:
$CI->session->whatever();


Hope this helps Smile