![]() |
Problem with CI4 session - 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: Problem with CI4 session (/showthread.php?tid=75055) |
Problem with CI4 session - webdevron - 12-15-2019 Do not know why, the session in the constructor is not working but in other method. Help me to find this out. Thanks in advance. PHP Code: <?php RE: Problem with CI4 session - InsiteFX - 12-15-2019 I load my session in the BaseController like below and it works just fine. Add a: PHP Code: use Config\Services; PHP Code: // Ensure that the session is started and running By the way I use the session files driver and save my sessions to the writable folder. RE: Problem with CI4 session - webdevron - 12-15-2019 Now I am loading session in my BaseController. PHP Code: <?php Then in my Controller. But still the same result. PHP Code: <?php RE: Problem with CI4 session - InsiteFX - 12-16-2019 You do not need the initController in a regular controller it is inherited from the BaseController, as long as you extend your controllers from BaseController. Just load your session in the BaseController then access the session in any method. RE: Problem with CI4 session - InsiteFX - 12-16-2019 BaseController: PHP Code: <?php Create new Test Controller: PHP Code: <?php namespace App\Controllers; Add this to the bottom of Views welcome_message.php PHP Code: <p> You will see that sessions do work. RE: Problem with CI4 session - asepma - 04-24-2020 please help. i have a libary code like bellow libarary <?php namespace App\Libraries\Mylibrary; class Mylibrary{ function hitung(){ $angka = 2; return $angka; } } controller : <?php namespace App\Controllers; use App\Libraries\Mylibrary; class Home extends BaseController { function sesi(){ $this->session->set('abc','item'); if ($this->session->get('abc')!='item') { echo "string"; }else{ echo "strong"; } echo hitung(); } } the error Call to undefined function App\Controllers\hitung() thanks. RE: Problem with CI4 session - InsiteFX - 04-24-2020 PHP Code: $lib = new Mylibrary(); Or autoload the library. |