Revision #5 has been created by benkevich on Jul 7, 2011, 3:02:22 PM with the memo:
will generate error if trying to access not existent objects property, one should check array value and not values property
« previous (#4) next (#6) »
Changes
Title
unchanged
Cookie management in Yii
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
cookies, cookie
Content
changed
[...]
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". To 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 : '';
```[...]
```php
$is_cookie = !emptyisset(Yii::app()->request->cookies['cookie_name']
->value);
```
### Reload required
Please, remember that server has actually **nothing** to do with the cookies. It only inform browser (in request result) about changes to cookies. Browser is responsible to do the job.[...]