CI4: not getting session data in another controller |
Dear Sir,
In Auth Controller, I have set session data and redirect to Homepage controller but I am unable to get session data in Homepage controller. Please find below code. In Auth.php (Controller) $mySess = session(); $mySess->set($data); // $this->session->set($data); return redirect()->to(site_url("homepage")); In Homepage (Controller) <?php namespace App\Controllers; use CodeIgniter\Controller; class Homepage extends BaseController { public function index() { $mySess = session(); $sessionArray = $mySess->get(); print_r($sessionArray); exit(); } //-------------------------------------------------------------------- } as a result I am getting blank page. Please help.
Once you load the session it is loaded for all controllers etc;
Just use. PHP Code: // using the helper I load the session library in the Base controller then it is global to all. PHP Code: <?php I then use the helper with chaining to do what I need but you can call it using PHP Code: $this-session->get('item'); What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |