在Cakephp 3上写入会话

在Cakephp 3上写入会话,php,cakephp,cakephp-3.0,Php,Cakephp,Cakephp 3.0,我试图将$this->Request->数据存储在会话中,以便在不同的控制器中再次使用它,但当我这样做时,会收到一条错误消息 守则: $x_hours = $this->request->data; $this->Session->write('x_hours', $x_hours); 我得到的错误是: 错误:对布尔函数调用成员函数write() 文件\src\Controller\HomeController.php 电话:59 我做错了什么 提前感谢您的支持。您需要

我试图将$this->Request->数据存储在会话中,以便在不同的控制器中再次使用它,但当我这样做时,会收到一条错误消息

守则:

$x_hours = $this->request->data;
$this->Session->write('x_hours', $x_hours);
我得到的错误是:

错误:对布尔函数调用成员函数write() 文件\src\Controller\HomeController.php 电话:59

我做错了什么


提前感谢您的支持。

您需要在CakePHP 3中使用
$this->request->session()
而不是
$this->session
:-

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

详细信息可以在中找到。

您需要在CakePHP 3中使用
$this->request->session()
而不是
$this->session
:-

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

详细信息可以在中找到。

谢谢,成功了。3.6+:
$this->getRequest()->getSession()
谢谢,成功了。3.6+:
$this->getRequest()->getSession()