1

I want to set the config for the cookie component but I am unsure where to add the code.

Do I set it in the AppController or the bootstrap?

public function initialize()
{
    parent::initialize();

    $this->loadComponent('Csrf');

    $this->Cookie->config([
        'httpOnly' => true
    ]);

}
Keith Power
  • 13,891
  • 22
  • 66
  • 135

1 Answers1

2

According to 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.

Assuming that you need to configure it globally, you should place the configurationcode into the initialize() of the AppController.

If you want to override the configuration at runtime, you can place the code into the beforeFilter() of a controller.

Sevvlor
  • 560
  • 1
  • 7
  • 24
  • I did try the `initialize()` in the `AppController` but I get a Fatal Error - `Error: Call to a member function config() on a non-object` – Keith Power Nov 23 '15 at 12:30
  • 2
    have you loaded the component using `$this->loadComponent('Cookie');`? – Sevvlor Nov 23 '15 at 12:34
  • 1
    Yes thank you. After reading the supplied link to the doc I noticed my error and I had just implemented the correction `$this->loadComponent('Cookie', ['httpOnly' => true]);` – Keith Power Nov 23 '15 at 12:37