CookieComponent Class Info:

Class Declaration:

class CookieComponent extends Component

File name:
Cake/Controller/Component/CookieComponent.php
Description:

Cookie Component.

Cookie handling for the controller.

Class Inheritance

Component Object

Properties:

Show/Hide parent properties
  • _Collection ComponentCollection

    Component collection class used to lazy load components.

  • _componentMap array

    A component lookup table used to lazy load component objects.

  • components array

    Other Components this component uses.

  • domain string

    Domain path.

    The domain that the cookie is available.

    Overridden with the controller beforeFilter(); $this->Cookie->domain = '.example.com';

    To make the cookie available on all subdomains of example.com. Set $this->Cookie->domain = '.example.com'; in your controller beforeFilter

  • _expires string

    Expire time of the cookie

    This is controlled by CookieComponent::time;

  • httpOnly boolean

    HTTP only cookie

    Set to true to make HTTP only cookies. Cookies that are HTTP only are not accessible in Javascript.

  • key string

    Encryption key.

    Overridden with the controller beforeFilter(); $this->Cookie->key = 'SomeRandomString';

  • name string

    The name of the cookie.

    Overridden with the controller beforeFilter(); $this->Cookie->name = 'CookieName';

  • path string

    Cookie path.

    Overridden with the controller beforeFilter(); $this->Cookie->path = '/';

    The path on the server in which the cookie will be available on. If public $cookiePath is set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the entire domain.

  • _reset string

    Used to reset cookie time if $expire is passed to CookieComponent::write()

  • _response CakeResponse

    A reference to the Controller's CakeResponse object

  • secure boolean

    Secure HTTPS only cookie.

    Overridden with the controller beforeFilter(); $this->Cookie->secure = true;

    Indicates that the cookie should only be transmitted over a secure HTTPS connection. When set to true, the cookie will only be set if a secure connection exists.

  • settings array

    Settings for this Component

  • time mixed

    The time a cookie will remain valid.

    Can be either integer Unix timestamp or a date string.

    Overridden with the controller beforeFilter(); $this->Cookie->time = '5 Days';

  • _type string

    Type of encryption to use.

    Currently only one method is available Defaults to Security::cipher();

  • _values string

    Values stored in the cookie.

    Accessed in the controller using $this->Cookie->read('Name.key');

beforeRedirect

top

Called before Controller::redirect(). Allows you to replace the url that will be redirected to with a new url. The return of this method can either be an array or a string.

If the return is an array and contains a 'url' key. You may also supply the following:

  • status The status code for the redirect
  • exit Whether or not the redirect should exit.

If your response is a string or an array that does not contain a 'url' key it will be used as the new url to redirect to.

Parameters:
  • Controller $controller required

    Controller with components to beforeRedirect

  • string|array $url required

    Either the string or url array that is being redirected to.

  • integer $status optional NULL

    The status code of the redirect

  • boolean $exit optional true

    Will the script exit.

Method defined in:
Cake/Controller/Component.php on line 162
Return

array|null Either an array or null.

Link
@link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect

beforeRender

top

Called before the Controller::beforeRender(), and before the view class is loaded, and before Controller::render()

Parameters:
  • Controller $controller required

    Controller with components to beforeRender

Method defined in:
Cake/Controller/Component.php on line 130

__construct

top

Constructor

Parameters:
  • ComponentCollection $collection required

    A ComponentCollection for this component

  • array $settings optional array ( )

    Array of settings.

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 169

_decrypt

top

Decrypts $value using public $type method in Security class

Parameters:
  • array $values required

    Values to decrypt

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 452
Return

string decrypted string

_delete

top

Sets a cookie expire time to remove cookie value

Parameters:
  • string $name required

    Name of cookie

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 415
Return

void

delete

top

Delete a cookie value

Optional [Name.], required key $this->Cookie->read('Name.key);

You must use this method before any output is sent to the browser. Failure to do so will result in header already sent errors.

Parameters:
  • string $key required

    Key of the value to be deleted

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 297

destroy

top

Destroy current cookie

You must use this method before any output is sent to the browser. Failure to do so will result in header already sent errors.

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 327

dispatchMethod

top

Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array

Parameters:
  • string $method required

    Name of the method to call

  • array $params optional array ( )

    Parameter list to use when calling $method

Method defined in:
Cake/Core/Object.php on line 110
Return

mixed Returns the result of the method call

_encrypt

top

Encrypts $value using public $type method in Security class

Parameters:
  • string $value required

    Value to encrypt

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 434
Return

string encrypted string

string Encoded values

_expire

top

Set the expire time for a session variable.

Creates a new expire time for a session variable. $expire can be either integer Unix timestamp or a date string.

Used by write() CookieComponent::write(string, string, boolean, 8400); CookieComponent::write(string, string, boolean, '5 Days');

Parameters:
  • mixed $expires optional NULL

    Can be either Unix timestamp, or date string

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 368
Return

integer Unix timestamp

_explode

top

Explode method to return array from string set in CookieComponent::_implode() Maintains reading backwards compatibility with 1.x CookieComponent::_implode().

Parameters:
  • string $string required

    A string containing JSON encoded data, or a bare string.

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 497
Return

array Map of key and values

__get

top

Magic method for lazy loading $components.

Parameters:
  • string $name required

    Name of component to get.

Method defined in:
Cake/Controller/Component.php on line 92
Return

mixed A Component object or null.

_implode

top

Implode method to keep keys are multidimensional arrays

Parameters:
  • array $array required

    Map of key and values

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 486
Return

string A json encoded string.

initialize

top

Called before the Controller::beforeFilter().

Parameters:
  • Controller $controller required

    Controller with components to initialize

Method defined in:
Cake/Controller/Component.php on line 109

log

top

Convenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.

Parameters:
  • string $msg required

    Log message

  • integer $type optional 2

    Error type constant. Defined in app/Config/core.php.

Method defined in:
Cake/Core/Object.php on line 149
Return

boolean Success of log write

_mergeVars

top

Merges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'

This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.

Parameters:
  • array $properties required

    The name of the properties to merge.

  • string $class required

    The class to merge the property with.

  • boolean $normalize optional true

    Set to true to run the properties through Set::normalize() before merging.

Method defined in:
Cake/Core/Object.php on line 187
Return

void

read

top

Read the value of the $_COOKIE[$key];

Optional [Name.], required key $this->Cookie->read(Name.key);

Parameters:
  • mixed $key optional NULL

    Key of the value to be obtained. If none specified, obtain map key => values

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 259

requestAction

top

Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.

Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()

Passing POST and GET data

POST and GET data can be simulated in requestAction. Use $extra['url'] for GET data. The $extra['data'] parameter allows POST data simulation.

Parameters:
  • mixed $url required

    String or array-based url. Unlike other url arrays in CakePHP, this url will not automatically handle passed and named arguments in the $url parameter.

  • array $extra optional array ( )

    if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.

Method defined in:
Cake/Core/Object.php on line 66
Return

mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.

_set

top

Allows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.

Parameters:
  • array $properties optional array ( )

    An associative array containing properties and corresponding values.

Method defined in:
Cake/Core/Object.php on line 164
Return

void

shutdown

top

Called after Controller::render() and before the output is printed to the browser.

Parameters:
  • Controller $controller required

    Controller with components to shutdown

Method defined in:
Cake/Controller/Component.php on line 140

startup

top

Start CookieComponent for use in the controller

Parameters:
  • Controller $controller required

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 190
Return

void

_stop

top

Stop execution of the current script. Wraps exit() making testing easier.

Parameters:
Method defined in:
Cake/Core/Object.php on line 137
Return

void

toString

top

Object-to-string conversion. Each class can override this method as necessary.

Method defined in:
Cake/Core/Object.php on line 41
Return

string The name of this class

type

top

Will allow overriding default encryption method.

Parameters:
  • string $type optional 'cipher'

    Encryption method

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 351
Return

void

Todo

NOT IMPLEMENTED

write

top

Write a value to the $_COOKIE[$key];

Optional [Name.], required key, optional $value, optional $encrypt, optional $expires $this->Cookie->write('[Name.]key, $value);

By default all values are encrypted. You must pass $encrypt false to store values in clear test

You must use this method before any output is sent to the browser. Failure to do so will result in header already sent errors.

Parameters:
  • mixed $key required

    Key for the value

  • mixed $value optional NULL

    Value

  • boolean $encrypt optional true

    Set to true to encrypt value, false otherwise

  • string $expires optional NULL

    Can be either Unix timestamp, or date string

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 218

_write

top

Set cookie

Parameters:
  • string $name required

    Name for cookie

  • string $value required

    Value for cookie

Method defined in:
Cake/Controller/Component/CookieComponent.php on line 392
Return

void