Welcome Guest, Not a member yet? Register   Sign In
Call to a member function get() on null Error
#1

Sometimes weird things happens...
I'm developing my web site locally on my PC...things run quite fine...
I have installed Codeigniter Shield ...and now I got the following error:

[Image: basecontroller_error.png]

Any help or hint to fix the issue? Thanks a lot

In my Base Controller I have the following code to have multi language functions:
Code:
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request, $response, $logger);
        // Preload any models, libraries, etc, here.
        // E.g.: $this->session = service('session');
/**
        * E.g.: $this->session = \Config\Services::session();
        * Ensure that the session is started and running
        */
        if (session_status() == PHP_SESSION_NONE) {
$this->session = Services::session();
        }
$config = new App();
        $language = \Config\Services::language();
        $locale = $this->session->get('locale') ?? $this->request->getLocale();
        $language->setLocale($locale);
       
        $this->viewData['locale'] = $locale;
        $this->viewData['supportedLocales'] = $config->supportedLocales;
    }
Reply
#2

To quote the documentation Initializing a Session:
Quote:Sessions will typically run globally with each page load, so the Session class should be magically initialized.
Languages are already also handled by Localization. I don't know why you're reinventing the wheel in your BaseController, but stop it.
Reply
#3

(This post was last modified: 4 hours ago by Vespa.)

Thanks for feedback and hints grimpirate, I really appreciate it.
I don't wanto to reinvent the wheel... I'm trying to add a feature ( just a Selection menu in header page) to allow users to switch among the languages in supportedLocales array.
For what I know ( very poor ) Codeigniter has no such features...but any suggestion on this is appreciated.

I got the issue...
The following code doesn't work anymore, ( weird...it worked fine before Shield installation ):
Code:
if (session_status() == PHP_SESSION_NONE){}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB