Class yii\web\CookieCollection
Inheritance | yii\web\CookieCollection » yii\base\BaseObject |
---|---|
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\BaseObject |
__construct() | Constructor. | yii\web\CookieCollection |
__get() | Returns the value of an object property. | yii\base\BaseObject |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() | Sets value of an object property. | yii\base\BaseObject |
__unset() | Sets an object property to null. | yii\base\BaseObject |
add() | Adds a cookie to the collection. | yii\web\CookieCollection |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
count() | 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() | 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\BaseObject |
hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() | Initializes the object. | yii\base\BaseObject |
offsetExists() | yii\web\CookieCollection | |
offsetGet() | yii\web\CookieCollection | |
offsetSet() | yii\web\CookieCollection | |
offsetUnset() | 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
The number of cookies in the collection.
An iterator for traversing the cookies in the collection.
Whether this collection is read only.
Method Details
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 |
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 |
---|
public void count ( ) |
Populates the cookie collection from an array.
public void fromArray ( array $array ) | ||
$array | array | The cookies to populate from |
Returns the cookie with the specified name.
See also getValue().
public yii\web\Cookie|null get ( $name ) | ||
$name | string | The cookie name |
return | yii\web\Cookie|null | The cookie with the specified name. Null if the named cookie does not exist. |
---|
Returns the number of cookies in the collection.
public integer getCount ( ) | ||
return | integer | The number of cookies in the collection. |
---|
public void getIterator ( ) |
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. |
---|
Returns whether there is a cookie with the specified name.
Note that if a cookie is marked for deletion from browser or its value is an empty string, this method will return false.
See also remove().
public boolean has ( $name ) | ||
$name | string | The cookie name |
return | boolean | Whether the named cookie exists |
---|
public void offsetExists ( $name ) | ||
$name |
public void offsetGet ( $name ) | ||
$name |
public void offsetSet ( $name, $cookie ) | ||
$name | ||
$cookie |
public void offsetUnset ( $name ) | ||
$name |
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 |
---|
Removes all cookies.
public void removeAll ( ) | ||
throws | yii\base\InvalidCallException | if the cookie collection is read only |
---|
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. |
---|