vir*_*ido 3 cookies middleware cakephp cakephp-3.0
我有问题在Cakephp 3.5.x中使用cookie.
在早期版本中,我使用了Cookie组件,但现在已弃用.我不清楚如何使用这个新的中间件来读写cookie.
该文档还不清楚我.它向我展示了如何设置cookie中间件,而不是如何处理在控制器中创建cookie.是否有人在3.5.x中处理过cookie?
中间件只替换了Cookie组件的加密部分(基本上它是CakePHP 3.0的唯一功能),如果需要,它会自动加密和解密你配置的cookie.
您不使用中间件来读取或写入cookie,这是通过请求和响应对象完成的,这是CakePHP 3以来的默认设置.
从控制器操作中读取和写入cookie可以很简单:
$rememberMe = $this->request->getCookie('remember_me');
Run Code Online (Sandbox Code Playgroud)
$this->response = $this->response->withCookie('remember_me', [
'value' => 'yes',
'path' => '/',
'httpOnly' => true,
'secure' => false,
'expire' => strtotime('+1 year')
]);
Run Code Online (Sandbox Code Playgroud)
也可以看看
| 归档时间: |
|
| 查看次数: |
1944 次 |
| 最近记录: |