2017-06-01 53 views
0

我試圖在會話中存儲$ this-> Request-> Data,這樣我就可以在不同的控制器中再次使用它,但是當我這樣做時,我收到一條錯誤消息。在CakePHP 3上寫入會話

代碼:

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

我得到的錯誤是:

錯誤:59:布爾 文件的\ src \控制器\ HomeController.php 行調用一個成員函數的write()

我在做什麼錯?

在此先感謝您的支持。

回答

3

你需要在CakePHP中3使用$this->request->session()而非$this->Session: -

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

詳細信息可在official docs找到。

+1

謝謝,就是這麼做的。 – aniga