CI4: not getting session data in another controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: CI4: not getting session data in another controller (/showthread.php?tid=76404) |
CI4: not getting session data in another controller - bhuvnesh.maheta - 05-10-2020 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. RE: CI4: not getting session data in another controller - cristobal - 04-06-2021 I've the same problem can you tell me how you solved it? RE: CI4: not getting session data in another controller - InsiteFX - 04-06-2021 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'); |