Cookie Component.
Provides enhanced cookie handling features for use in the controller layer. In addition to the basic features offered be Cake\Network\Response, this class lets you:
_delete( string $name )
Sets a cookie expire time to remove cookie value.
This is only done once all values in a cookie key have been removed with delete.
$name
_getCookieEncryptionKey( )
Returns the encryption key to be used.
string
_load( string|array $key )
Load the cookie data from the request and response objects.
Based on the configuration data, cookies will be decrypted. When cookies contain array data, that data will be expanded.
$key
_write( string $name , string $value )
Set cookie
$name
$value
check( string|null $key null )
Returns true if given key is set in the cookie.
$key
optional null boolean
configKey( string $keyname , null|string|array $option null , string|null $value null )
Set the configuration for a specific top level key.
Set a single config option for a key:
$this->Cookie->configKey('User', 'expires', '+3 months');
Set multiple options:
$this->Cookie->configKey('User', [ 'expires', '+3 months', 'httpOnly' => true, ]);
$keyname
$option
optional null $value
optional null array|null
delete( string $key )
Delete a cookie value
You must use this method before any output is sent to the browser. Failure to do so will result in header already sent errors.
Deleting a top level key will delete all keys nested within that key. For example deleting the User
key, will also delete User.email
.
$key
implementedEvents( )
Events supported by this component.
array
Cake\Controller\Component::implementedEvents()
initialize( array $config )
Initialize config data and properties.
$config
Cake\Controller\Component::initialize()
read( string|null $key null )
Read the value of key path from request cookies.
This method will also allow you to read cookies that have been written in this request, but not yet sent to the client.
$key
optional null string
write( string|array $key , mixed $value null )
Write a value to the response cookies.
You must use this method before any output is sent to the browser. Failure to do so will result in header already sent errors.
$key
$value
optional null __construct( Cake\Controller\ComponentRegistry $registry , array $config [] )
Constructor
Cake\Controller\ComponentRegistry
$registry
$config
optional [] __debugInfo( )
Returns an array that can be used to describe the internal state of this object.
array
__get( string $name )
Magic method for lazy loading $components.
$name
mixed
_checkCipher( string $encrypt )
Helper method for validating encryption cipher names.
$encrypt
RuntimeException
_decode( string $value , string|false $encrypt )
Decodes and decrypts a single value.
$value
$encrypt
string
_decrypt( array $values , string|boolean $mode )
Decrypts $value using public $type method in Security class
$values
$mode
string
_encrypt( string $value , string|boolean $encrypt , string|null $key null )
Encrypts $value using public $type method in Security class
$value
$encrypt
$key
optional null string
_explode( string $string )
Explode method to return array from string set in CookieComponent::_implode() Maintains reading backwards compatibility with 1.x CookieComponent::_implode().
$string
array
_implode( array $array )
Implode method to keep keys are multidimensional arrays
$array
string
_configDelete( string $key )
Delete a single config key
$key
Cake\Core\Exception\Exception
_configRead( string|null $key )
Read a config variable
$key
mixed
_configWrite( string|array $key , mixed $value , boolean|string $merge false )
Write a config variable
$key
$value
$merge
optional false Cake\Core\Exception\Exception
config( string|array|null $key null , mixed|null $value null , boolean $merge true )
Reading the whole config:
$this->config();
Reading a specific value:
$this->config('key');
Reading a nested value:
$this->config('some.nested.key');
Setting a specific value:
$this->config('key', $value);
Setting a nested value:
$this->config('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->config(['one' => 'value', 'another' => 'value']);
$key
optional null $value
optional null $merge
optional true mixed
Cake\Core\Exception\Exception
configShallow( string|array $key , mixed|null $value null )
Merge provided config with existing config. Unlike config()
which does a recursive merge for nested keys, this method does a simple merge.
Setting a specific value:
$this->config('key', $value);
Setting a nested value:
$this->config('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->config(['one' => 'value', 'another' => 'value']);
$key
$value
optional null mixed
log( mixed $msg , integer|string $level LogLevel::ERROR , string|array $context [] )
Convenience method to write a message to Log. See Log::write() for more information on writing to logs.
$msg
$level
optional LogLevel::ERROR $context
optional [] boolean
protected array
A component lookup table used to lazy load component objects.
[]
protected Cake\Controller\ComponentRegistry
Component registry class used to lazy load components.
protected boolean
Whether the config property has already been configured with defaults
false
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/3.1/class-Cake.Controller.Component.CookieComponent.html