PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 22, 2022

[FIXED] Where to set CakePHP 3 cookie config

 February 22, 2022     cakephp-3.0, cakephp-3.1     No comments   

Issue

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
    ]);

}

Solution

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.



Answered By - Sevvlor
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing