How to read and write Session in Cakephp 3.0

ぐ巨炮叔叔 提交于 2019-12-03 03:08:59

You need to set $session :

$session = $this->request->session();
$session->write('Config.language', 'eng'); 
$session->read('Config.language');

And then you'll be able to read and write in your session

Or you can direclty read and write :

$this->request->session()->write('Config.language', 'eng');
$this->request->session()->read('Config.language');

I use this its works fine

$session = $this->request->session();
$session->write('annul_income','$100,00,00');//Write
echo $session->read('annul_income')//To read the session value   o/p:$100,00,00

Prior to 3.6.0 use getRequest() and getSession() instead.

$name = $this->getRequest()->getSession()->read('User.name');

And if you are accessing the session multiple times, you will probably want a local variable.

$session = $this->getRequest()->getSession();
$name = $session->read('User.name');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!