How to create cookies at controller level in CakePHP 3.5?

╄→гoц情女王★ 提交于 2019-11-29 15:10:36

The middleware only replaces the encryption part of the Cookie component (which basically is the only thing it did as of CakePHP 3.0 anyways), if required it automatically encrypts and decrypts the cookies that you've configured.

You do not use the middleware to read or write cookies, that is done via the request and response objects, which is the default since CakePHP 3.

Reading and writing cookies from within a controller action can be as simple as:

$rememberMe = $this->request->getCookie('remember_me');
$this->response = $this->response->withCookie('remember_me', [
    'value' => 'yes',
    'path' => '/',
    'httpOnly' => true,
    'secure' => false,
    'expire' => strtotime('+1 year')
]);

See also

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!