W3cubDocs

/Yii 2.0

Class yii\web\CookieCollection

Inheritance yii\web\CookieCollection » yii\base\Object
Implements ArrayAccess, Countable, IteratorAggregate, yii\base\Configurable
Available since version 2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php

CookieCollection maintains the cookies available in the current request.

For more details and usage information on CookieCollection, see the guide article on handling cookies.

Public Properties

Property Type Description Defined By
$count integer The number of cookies in the collection. yii\web\CookieCollection
$iterator ArrayIterator An iterator for traversing the cookies in the collection. yii\web\CookieCollection
$readOnly boolean Whether this collection is read only. yii\web\CookieCollection

Public Methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\Object
__construct() Constructor. yii\web\CookieCollection
__get() Returns the value of an object property. yii\base\Object
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Object
__set() Sets value of an object property. yii\base\Object
__unset() Sets an object property to null. yii\base\Object
add() Adds a cookie to the collection. yii\web\CookieCollection
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Object
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Object
className() Returns the fully qualified name of this class. yii\base\Object
count() Returns the number of cookies in the collection. yii\web\CookieCollection
fromArray() Populates the cookie collection from an array. yii\web\CookieCollection
get() Returns the cookie with the specified name. yii\web\CookieCollection
getCount() Returns the number of cookies in the collection. yii\web\CookieCollection
getIterator() Returns an iterator for traversing the cookies in the collection. yii\web\CookieCollection
getValue() Returns the value of the named cookie. yii\web\CookieCollection
has() Returns whether there is a cookie with the specified name. yii\web\CookieCollection
hasMethod() Returns a value indicating whether a method is defined. yii\base\Object
hasProperty() Returns a value indicating whether a property is defined. yii\base\Object
init() Initializes the object. yii\base\Object
offsetExists() Returns whether there is a cookie with the specified name. yii\web\CookieCollection
offsetGet() Returns the cookie with the specified name. yii\web\CookieCollection
offsetSet() Adds the cookie to the collection. yii\web\CookieCollection
offsetUnset() Removes the named cookie. yii\web\CookieCollection
remove() Removes a cookie. yii\web\CookieCollection
removeAll() Removes all cookies. yii\web\CookieCollection
toArray() Returns the collection as a PHP array. yii\web\CookieCollection

Property Details

$count public read-only property

The number of cookies in the collection.

public integer getCount ( )

$iterator public read-only property

An iterator for traversing the cookies in the collection.

public ArrayIterator getIterator ( )

$readOnly public property

Whether this collection is read only.

public boolean $readOnly = false

Method Details

__construct() public method

Constructor.

public void __construct ( $cookies = [], $config = [] )
$cookies array

The cookies that this collection initially contains. This should be an array of name-value pairs.

$config array

Name-value pairs that will be used to initialize the object properties

add() public method

Adds a cookie to the collection.

If there is already a cookie with the same name in the collection, it will be removed first.

public void add ( $cookie )
$cookie yii\web\Cookie

The cookie to be added

throws yii\base\InvalidCallException

if the cookie collection is read only

count() public method

Returns the number of cookies in the collection.

This method is required by the SPL Countable interface. It will be implicitly called when you use count($collection).

public integer count ( )
return integer

The number of cookies in the collection.

fromArray() public method (available since version 2.0.3)

Populates the cookie collection from an array.

public void fromArray ( array $array )
$array array

The cookies to populate from

get() public method

Returns the cookie with the specified name.

See also getValue().

public yii\web\Cookie get ( $name )
$name string

The cookie name

return yii\web\Cookie

The cookie with the specified name. Null if the named cookie does not exist.

getCount() public method

Returns the number of cookies in the collection.

public integer getCount ( )
return integer

The number of cookies in the collection.

getIterator() public method

Returns an iterator for traversing the cookies in the collection.

This method is required by the SPL interface IteratorAggregate. It will be implicitly called when you use foreach to traverse the collection.

public ArrayIterator getIterator ( )
return ArrayIterator

An iterator for traversing the cookies in the collection.

getValue() public method

Returns the value of the named cookie.

See also get().

public mixed getValue ( $name, $defaultValue = null )
$name string

The cookie name

$defaultValue mixed

The value that should be returned when the named cookie does not exist.

return mixed

The value of the named cookie.

has() public method

Returns whether there is a cookie with the specified name.

Note that if a cookie is marked for deletion from browser, this method will return false.

See also remove().

public boolean has ( $name )
$name string

The cookie name

return boolean

Whether the named cookie exists

offsetExists() public method

Returns whether there is a cookie with the specified name.

This method is required by the SPL interface ArrayAccess. It is implicitly called when you use something like isset($collection[$name]).

public boolean offsetExists ( $name )
$name string

The cookie name

return boolean

Whether the named cookie exists

offsetGet() public method

Returns the cookie with the specified name.

This method is required by the SPL interface ArrayAccess. It is implicitly called when you use something like $cookie = $collection[$name];. This is equivalent to get().

public yii\web\Cookie offsetGet ( $name )
$name string

The cookie name

return yii\web\Cookie

The cookie with the specified name, null if the named cookie does not exist.

offsetSet() public method

Adds the cookie to the collection.

This method is required by the SPL interface ArrayAccess. It is implicitly called when you use something like $collection[$name] = $cookie;. This is equivalent to add().

public void offsetSet ( $name, $cookie )
$name string

The cookie name

$cookie yii\web\Cookie

The cookie to be added

offsetUnset() public method

Removes the named cookie.

This method is required by the SPL interface ArrayAccess. It is implicitly called when you use something like unset($collection[$name]). This is equivalent to remove().

public void offsetUnset ( $name )
$name string

The cookie name

remove() public method

Removes a cookie.

If $removeFromBrowser is true, the cookie will be removed from the browser. In this case, a cookie with outdated expiry will be added to the collection.

public void remove ( $cookie, $removeFromBrowser = true )
$cookie yii\web\Cookie|string

The cookie object or the name of the cookie to be removed.

$removeFromBrowser boolean

Whether to remove the cookie from browser

throws yii\base\InvalidCallException

if the cookie collection is read only

removeAll() public method

Removes all cookies.

public void removeAll ( )
throws yii\base\InvalidCallException

if the cookie collection is read only

toArray() public method

Returns the collection as a PHP array.

public array toArray ( )
return array

The array representation of the collection. The array keys are cookie names, and the array values are the corresponding cookie objects.

© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-web-cookiecollection.html