How to read session variable in bootstrp.php file in Cakephp3

210 Views Asked by At

I have to read session variable into bootstrap.php file and have to assign this to a variable. When I am accessing session variable I am getting error:

Error: Call to a member function session() on null.

Below is my code.

   $year=$this->request->session()->read('Auth.User.year');
     Configure::write('Theme', [
    'logo' => [
       'large' => "<b>FlexiComs</b>$year"
        ],
   ]);
1

There are 1 best solutions below

0
floriank On

bootstrap.php is the wrong place.

Write the data to your config and write the data to the session in your app controllers initialize() by reading it there from your config.

App related logic does not belong into the bootstrap process.