Revision #4 has been created by Rodrigo Coelho on Apr 20, 2011, 4:25:57 PM with the memo:
small typo correction
« previous (#3) next (#5) »
Changes
Title
unchanged
Cookie management in Yii
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
cookies, cookie
Content
changed
[...]
Cookies in Yii are read from [CHttpCookie](http://www.yiiframework.com/doc/api/1.1/CHttpCookie/ "") which is **an object**, that's why you have add **->value** to your code (see examples in previous chapter). If you omit that, you'll get warning or error saying that object of class CHttpCookie cannot be converted to a string.
### Safe reading
On the same basis, as above, if a particular cookie does not exists, a corresponding object (CHttpCookie instance) for it will not be created! Trying to read such cookie will result in error "Trying to get property of non-object". ItTo avoid that, it is always better to read a cookie using ternary operator, like that:
```php
$cookie = (isset(Yii::app()->request->cookies['cookie_name']->value)) ? Yii::app()->request->cookies['cookie_name']->value : '';
```[...]