CodeIgniter Forums
$session - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: $session (/showthread.php?tid=52394)



$session - El Forum - 06-08-2012

[eluser]GI-Joe[/eluser]
Can I use session created in one controller in another controller.

say in Controller A
Code:
$this->session->set_userdata('data','somedata');

Can I use it in another controller

Controller B

Code:
echo $this->session->userdata('data');



$session - El Forum - 06-08-2012

[eluser]InsiteFX[/eluser]
Yes the sessions are global to your application. But if you need to access them from a library then you need to use the CodeIgniter Super Object.



$session - El Forum - 06-08-2012

[eluser]Otemu[/eluser]
Yes check out the session class

Quote:The Session class permits you maintain a user's "state" and track their activity while they browse your site.



$session - El Forum - 06-08-2012

[eluser]GI-Joe[/eluser]
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Admin::$session

Filename: controllers/admin.php

Line Number: 19

Fatal error: Call to a member function userdata() on a non-object in F:\xampp\htdocs\web\application\controllers\admin.php on line 19

Getting this error


$session - El Forum - 06-08-2012

[eluser]GI-Joe[/eluser]
How to get session data in constructor?


$session - El Forum - 06-09-2012

[eluser]InsiteFX[/eluser]
Autoload the session library in ./application/config/autoload.php



$session - El Forum - 06-09-2012

[eluser]GI-Joe[/eluser]
[quote author="InsiteFX" date="1339225230"]Autoload the session library in ./application/config/autoload.php
[/quote]
I have done that still can't get session data in constructor