![]() |
I'm trying to initialise Sessions in the BaseController but I'm getting error Attempt to read property "driver" on null
My Config\app variables public $sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler'; public $sessionCookieName = 'ci_session'; public $sessionExpiration = 7200; public $sessionSavePath = WRITEPATH . 'session'; public $sessionTimeToUpdate = 300; My Base class Code: <?php
Here is my Config\Service class
Code: <?php I don't have Config\Session, Could be the reason I'm getting the above error? And if yes, what do I need to put in the file. (06-16-2024, 05:37 AM)jmuhwezi Wrote: My Config\app variables It seems your Config files are outdated. Now there is no $session* properties in Config\App. You need to set up "app/Config/Session.php". https://github.com/codeigniter4/CodeIgni...ession.php
thanks @kenjis you right I have outdated files. When I added the Session.php file, it created another error: foreach() argument must be of type array|object, string given, which seem to be in the service file around the getIpAddress.
can you guide on the same as well? Code: ErrorException Code: SYSTEMPATH/HTTP/RequestTrait.php at line 87 Code: SYSTEMPATH/HTTP/RequestTrait.php : 87 — CodeIgniter\Debug\Exceptions->errorHandler ( arguments )
It is because your Config\App is still outofdated.
Update $proxyIPs value. https://github.com/codeigniter4/CodeIgni...p.php#L183 If you are using git, I recommend you copy all the latest Config/*.php file into your project, and check the differences and apply updates in items that you did not change.
Yes I'm using git @kenjis, and I have copied the Config\app file as guided. Do I still need to initialise session in BaseController file
Code: $this->session = \Config\Services::session(); Code: ErrorException Code: SYSTEMPATH/Session/Handlers/FileHandler.php at line 74 Code: {PHP internal code} — CodeIgniter\Debug\Exceptions->errorHandler ( arguments ) (06-16-2024, 09:02 PM)jmuhwezi Wrote: ini_set(): Session ini settings cannot be changed after headers have already been sent As the error message says, your app has already sent something before the call of \Config\Services:: session(). Remove the code to output something. It might be a white space or new line code or BOM (Byte Order Mark) in somewhere that is not needed. But the error should not happen if you write clean code. Try to install clean CI4 and add the code in BaseController, and check. You would probably see no error. |
Welcome Guest, Not a member yet? Register Sign In |