在哪里设置 CakePHP 3 cookie 配置
Where to set CakePHP 3 cookie config
我想为 cookie 组件设置配置,但我不确定在哪里添加代码。
我是在 AppController 还是 bootstrap 中设置它?
public function initialize()
{
parent::initialize();
$this->loadComponent('Csrf');
$this->Cookie->config([
'httpOnly' => true
]);
}
根据http://book.cakephp.org/3.0/en/controllers/components.html#configuring-components
Some examples of components requiring configuration are Authentication and Cookie. Configuration for these components, and for components in general, is usually done via loadComponent() in your Controller’s initialize() method or via the $components array.
假设你需要全局配置,你应该将配置代码放在AppController
的initialize()
中。
如果要在运行时覆盖配置,可以将代码放入控制器的 beforeFilter()
。
我想为 cookie 组件设置配置,但我不确定在哪里添加代码。
我是在 AppController 还是 bootstrap 中设置它?
public function initialize()
{
parent::initialize();
$this->loadComponent('Csrf');
$this->Cookie->config([
'httpOnly' => true
]);
}
根据http://book.cakephp.org/3.0/en/controllers/components.html#configuring-components
Some examples of components requiring configuration are Authentication and Cookie. Configuration for these components, and for components in general, is usually done via loadComponent() in your Controller’s initialize() method or via the $components array.
假设你需要全局配置,你应该将配置代码放在AppController
的initialize()
中。
如果要在运行时覆盖配置,可以将代码放入控制器的 beforeFilter()
。