CookieCollection

Type
Class
Namespace
Craft
Inherits
Craft\CookieCollection » CCookieCollection (opens new window) » CMap (opens new window) » CComponent (opens new window)
Implements
ArrayAccess (opens new window), Countable (opens new window), IteratorAggregate (opens new window)
Since
2.2

CookieCollection implements a collection class to store cookies. You normally access it via {@link HttpRequest::getCookies()}.

Since CookieCollection ultimately extends from {@link CMap}, it can be used like an associative array as follows:

$cookies[$name] = new HttpCookie($name, $value); // sends a cookie
$value = $cookies[$name]->value; // reads a cookie value
unset($cookies[$name]);  // removes a cookie

See also http://craftcms.com

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__construct() (opens new window) Constructor.
__get() (opens new window) Returns a property value, an event handler list or a behavior based on its name.
__isset() (opens new window) Checks if a property value is null.
__set() (opens new window) Sets value of a component property.
__unset() (opens new window) Sets a component property to be null.
add() (opens new window) Adds an item into the map.
asa() (opens new window) Returns the named behavior object.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
attachEventHandler() (opens new window) Attaches an event handler to an event.
canGetProperty() (opens new window) Determines whether a property can be read.
canSetProperty() (opens new window) Determines whether a property can be set.
clear() (opens new window) Removes all items in the map.
contains() (opens new window)
copyFrom() (opens new window) Copies iterable data into the map.
count() (opens new window) Returns the number of items in the map.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
detachEventHandler() (opens new window) Detaches an existing event handler.
disableBehavior() (opens new window) Disables an attached behavior.
disableBehaviors() (opens new window) Disables all behaviors attached to this component.
enableBehavior() (opens new window) Enables an attached behavior.
enableBehaviors() (opens new window) Enables all behaviors attached to this component.
evaluateExpression() (opens new window) Evaluates a PHP expression or callback under the context of this component.
getCount() (opens new window) Returns the number of items in the map.
getEventHandlers() (opens new window) Returns the list of attached event handlers for an event.
getIterator() (opens new window) Returns an iterator for traversing the items in the list.
getKeys() (opens new window)
getReadOnly() (opens new window)
getRequest() (opens new window)
hasEvent() (opens new window) Determines whether an event is defined.
hasEventHandler() (opens new window) Checks whether the named event has attached handlers.
hasProperty() (opens new window) Determines whether a property is defined.
itemAt() (opens new window) Returns the item with the specified key.
mergeArray() (opens new window) Merges two or more arrays into one recursively.
mergeWith() (opens new window) Merges iterable data into the map.
offsetExists() (opens new window) Returns whether there is an element at the specified offset.
offsetGet() (opens new window) Returns the element at the specified offset.
offsetSet() (opens new window) Sets the element at the specified offset.
offsetUnset() (opens new window) Unsets the element at the specified offset.
raiseEvent() (opens new window) Raises an event.
remove() (opens new window) Removes an item from the map by its key.
toArray() (opens new window)

# Protected Methods

Method Description
addCookie() (opens new window) Sends a cookie.
getCookies() Returns a array of validated {@link HttpCookie} objects pulled from $_COOKIES.
removeCookie() (opens new window) Deletes a cookie.
setReadOnly() (opens new window)

# getCookies()

Returns a array of validated {@link HttpCookie} objects pulled from $_COOKIES. Since Craft uses it's own {@link HttpCookie} class, we're overriding this to prevent is from getting duplicate identity cookies in the case someone has 'defaultCookieDomain' set to something custom.

View source (opens new window)

Returns

array (opens new window) – The array of validated cookies

Signature

protected array getCookies ( )