| Package | system.web | 
|---|---|
| Inheritance | class CCookieCollection » CMap » CComponent | 
| Implements | Countable, ArrayAccess, Traversable, IteratorAggregate | 
| Since | 1.0 | 
| Version | $Id$ | 
| Source Code | framework/web/CHttpRequest.php | 
$cookies[$name]=new CHttpCookie($name,$value); // sends a cookie $value=$cookies[$name]->value; // reads a cookie value unset($cookies[$name]); // removes a cookie
| Property | Type | Description | Defined By | 
|---|---|---|---|
| count | integer | the number of items in the map | CMap | 
| iterator | CMapIterator | Returns an iterator for traversing the items in the list. | CMap | 
| keys | array | the key list | CMap | 
| readOnly | boolean | whether this map is read-only or not. | CMap | 
| request | CHttpRequest | the request instance | CCookieCollection | 
| Property | Type | Description | Defined By | 
|---|---|---|---|
| cookies | array | list of validated cookies | CCookieCollection | 
| Method | Description | Defined By | 
|---|---|---|
| __call() | Calls the named method which is not a class method. | CComponent | 
| __construct() | Constructor. | CCookieCollection | 
| __get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent | 
| __isset() | Checks if a property value is null. | CComponent | 
| __set() | Sets value of a component property. | CComponent | 
| __unset() | Sets a component property to be null. | CComponent | 
| add() | Inserts an item at the specified position. | CCookieCollection | 
| asa() | Returns the named behavior object. | CComponent | 
| attachBehavior() | Attaches a behavior to this component. | CComponent | 
| attachBehaviors() | Attaches a list of behaviors to the component. | CComponent | 
| attachEventHandler() | Attaches an event handler to an event. | CComponent | 
| canGetProperty() | Determines whether a property can be read. | CComponent | 
| canSetProperty() | Determines whether a property can be set. | CComponent | 
| clear() | Removes all items in the map. | CMap | 
| contains() | CMap | |
| copyFrom() | Copies iterable data into the map. | CMap | 
| count() | Returns the number of items in the map. | CMap | 
| detachBehavior() | Detaches a behavior from the component. | CComponent | 
| detachBehaviors() | Detaches all behaviors from the component. | CComponent | 
| detachEventHandler() | Detaches an existing event handler. | CComponent | 
| disableBehavior() | Disables an attached behavior. | CComponent | 
| disableBehaviors() | Disables all behaviors attached to this component. | CComponent | 
| enableBehavior() | Enables an attached behavior. | CComponent | 
| enableBehaviors() | Enables all behaviors attached to this component. | CComponent | 
| getCount() | Returns the number of items in the map | CMap | 
| getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent | 
| getIterator() | Returns an iterator for traversing the items in the list. | CMap | 
| getKeys() | Returns the key list | CMap | 
| getReadOnly() | Returns whether this map is read-only or not. Defaults to false. | CMap | 
| getRequest() | Returns the request instance | CCookieCollection | 
| hasEvent() | Determines whether an event is defined. | CComponent | 
| hasEventHandler() | Checks whether the named event has attached handlers. | CComponent | 
| hasProperty() | Determines whether a property is defined. | CComponent | 
| itemAt() | Returns the item with the specified key. | CMap | 
| mergeArray() | Merges two arrays into one recursively. | CMap | 
| mergeWith() | Merges iterable data into the map. | CMap | 
| offsetExists() | Returns whether there is an element at the specified offset. | CMap | 
| offsetGet() | Returns the element at the specified offset. | CMap | 
| offsetSet() | Sets the element at the specified offset. | CMap | 
| offsetUnset() | Unsets the element at the specified offset. | CMap | 
| raiseEvent() | Raises an event. | CComponent | 
| remove() | Removes an item at the specified position. | CCookieCollection | 
| toArray() | CMap | 
| Method | Description | Defined By | 
|---|---|---|
| addCookie() | Sends a cookie. | CCookieCollection | 
| getCookies() | Returns list of validated cookies | CCookieCollection | 
| removeCookie() | Deletes a cookie. | CCookieCollection | 
| setReadOnly() | Sets whether this list is read-only or not | CMap | 
list of validated cookies
the request instance
| 
public void __construct(CHttpRequest $request) | ||
| $request | CHttpRequest | owner of this collection. | 
public function __construct(CHttpRequest $request)
{
    $this->_request=$request;
    $this->copyfrom($this->getCookies());
    $this->_initialized=true;
}
Constructor.
| 
public void add(integer $name, mixed $cookie) | ||
| $name | integer | the specified position. | 
| $cookie | mixed | new item | 
public function add($name,$cookie)
{
    if($cookie instanceof CHttpCookie)
    {
        $this->remove($name);
        parent::add($name,$cookie);
        if($this->_initialized)
            $this->addCookie($cookie);
    }
    else
        throw new CException(Yii::t('yii','CHttpCookieCollection can only hold CHttpCookie objects.'));
}
Inserts an item at the specified position. This overrides the parent implementation by performing additional operations for each newly added CHttpCookie object.
| 
protected void addCookie(CHttpCookie $cookie) | ||
| $cookie | CHttpCookie | cook to be sent | 
protected function addCookie($cookie)
{
    $value=$cookie->value;
    if($this->_request->enableCookieValidation)
        $value=Yii::app()->getSecurityManager()->hashData($value);
    if(version_compare(PHP_VERSION,'5.2.0','>='))
        setcookie($cookie->name,$value,$cookie->expire,$cookie->path,$cookie->domain,$cookie->secure,$cookie->httpOnly);
    else
        setcookie($cookie->name,$value,$cookie->expire,$cookie->path,$cookie->domain,$cookie->secure);
}
Sends a cookie.
| 
protected array getCookies() | ||
| {return} | array | list of validated cookies | 
protected function getCookies()
{
    $cookies=array();
    if($this->_request->enableCookieValidation)
    {
        $sm=Yii::app()->getSecurityManager();
        foreach($_COOKIE as $name=>$value)
        {
            if(($value=$sm->validateData($value))!==false)
                $cookies[$name]=new CHttpCookie($name,$value);
        }
    }
    else
    {
        foreach($_COOKIE as $name=>$value)
            $cookies[$name]=new CHttpCookie($name,$value);
    }
    return $cookies;
}
| 
public CHttpRequest getRequest() | ||
| {return} | CHttpRequest | the request instance | 
public function getRequest()
{
    return $this->_request;
}
| 
public mixed remove(integer $name) | ||
| $name | integer | the index of the item to be removed. | 
| {return} | mixed | the removed item. | 
public function remove($name)
{
    if(($cookie=parent::remove($name))!==null)
    {
        if($this->_initialized)
            $this->removeCookie($cookie);
    }
    return $cookie;
}
Removes an item at the specified position. This overrides the parent implementation by performing additional cleanup work when removing a TCookie object.
| 
protected void removeCookie(CHttpCookie $cookie) | ||
| $cookie | CHttpCookie | cook to be deleted | 
protected function removeCookie($cookie)
{
    if(version_compare(PHP_VERSION,'5.2.0','>='))
        setcookie($cookie->name,null,0,$cookie->path,$cookie->domain,$cookie->secure,$cookie->httpOnly);
    else
        setcookie($cookie->name,null,0,$cookie->path,$cookie->domain,$cookie->secure);
}
Deletes a cookie.
Signup or Login in order to comment.