Devendra
Devendra

Reputation: 221

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

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"
        ],
   ]);

Upvotes: 0

Views: 213

Answers (1)

floriank
floriank

Reputation: 25698

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.

Upvotes: 2

Related Questions