没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Class yii\web\CookieCollection

继承yii\web\CookieCollection » yii\base\BaseObject
实现ArrayAccess, Countable, IteratorAggregate, yii\base\Configurable
可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/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.

公共属性

隐藏继承的属性

属性类型描述被定义在
$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

公共方法

隐藏继承的方法

方法描述被定义在
__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() 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\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
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

属性详情

$count 公共 只读 属性

The number of cookies in the collection.

public integer getCount ( )
$iterator 公共 只读 属性

An iterator for traversing the cookies in the collection.

$readOnly 公共 属性

Whether this collection is read only.

public boolean $readOnly false

方法详情

__construct() 公共 方法

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() 公共 方法

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() 公共 方法

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() 公共 方法 (自版本 2.0.3 可用)

Populates the cookie collection from an array.

public void fromArray(array $array)
$array array

The cookies to populate from

get() 公共 方法

Returns the cookie with the specified name.

参见 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() 公共 方法

Returns the number of cookies in the collection.

public integer getCount()
return integer

The number of cookies in the collection.

getIterator() 公共 方法

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() 公共 方法

Returns the value of the named cookie.

参见 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() 公共 方法

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.

参见 remove().

public boolean has($name)
$name string

The cookie name

return boolean

Whether the named cookie exists

offsetExists() 公共 方法

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() 公共 方法

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() 公共 方法

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() 公共 方法

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() 公共 方法

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() 公共 方法

Removes all cookies.

public void removeAll()
throws yii\base\InvalidCallException

if the cookie collection is read only

toArray() 公共 方法

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.