CodeIgniter Forums
Can session autoload? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Can session autoload? (/thread-73636.html)



Can session autoload? - Andryshok - 05-16-2019

Unfortunately what loved a Codeigniter earlier now for was lost - documentation very bad Huh
I create new project on CI 4
How i can autoload session
app/Config/Autoload.php
Code:
$psr4 = [
            'Config'      => APPPATH . 'Config',
            APP_NAMESPACE => APPPATH,                // For custom namespace
            'App'         => APPPATH,                // To ensure filters, etc still found,
            'Session'     => SYSPATH . 'Session',
            
        ];
Result - Warning: Use of undefined constant SYSPATH - assumed 'SYSPATH' (this will throw an Error in a future version of PHP)
Help


RE: Can session autoload? - rmcdahal - 05-16-2019

You can load session as


Code:
$session = \Config\Services::session($config);


in BaseController


RE: Can session autoload? - Andryshok - 05-16-2019

I don't use BaseController, i wont load session library in autoload, construction $session = \Config\Services:Confusedession($config) - not work in app/Config/Autoload.php


RE: Can session autoload? - ciadmin - 05-16-2019

The BaseController is intended to be the mechanism for providing the equivalent of autoloading from CI3 ... https://codeigniter4.github.io/userguide/extending/basecontroller.html

Your first post above is trying to create a Sessions namespace, which is not provided for in the framework.

CI4's app/Config/Autoload is meant to tell the PHP class loader where to find source code, and not to preload components for a request.