【问题标题】:Write to session on Cakephp 3写到 Cakephp 3 上的会话
【发布时间】:2017-06-01 13:12:38
【问题描述】:

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

代码:

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

我得到的错误是:

错误:在布尔值上调用成员函数 write() 文件 \src\Controller\HomeController.php 线路:59

我做错了什么?

提前感谢您的支持。

【问题讨论】:

    标签: php cakephp cakephp-3.0


    【解决方案1】:

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

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

    详情请见official docs

    【讨论】:

    • 谢谢,成功了。
    • 3.6+:$this->getRequest()->getSession()
    猜你喜欢
    • 2016-01-20
    • 2015-04-02
    • 2011-05-14
    • 2011-05-13
    • 2018-08-10
    • 2016-01-01
    • 2014-09-10
    • 2012-06-28
    • 2018-10-17
    相关资源
    最近更新 更多