aniga
aniga

Reputation: 117

Write to session on Cakephp 3

I am trying to store $this->Request->Data on a session so I can use it again in a different controller but when I do that I'm getting an error message.

The code:

$x_hours = $this->request->data;
$this->Session->write('x_hours', $x_hours);

The error I get is:

Error: Call to a member function write() on boolean File \src\Controller\HomeController.php Line: 59

What am I doing wrong?

Thanks in advance for your support.

Upvotes: 0

Views: 793

Answers (1)

drmonkeyninja
drmonkeyninja

Reputation: 8540

You need to use $this->request->session() rather than $this->Session in CakePHP 3:-

$this->request->session()->write('x_hours', $x_hours);

Details can be found in the official docs.

Upvotes: 3

Related Questions