Cookie management in Yii

Comparing #4 with #5

Revision #5 was created by benkevich benkevich on Jul 7, 2011, 3:02:22 PM.

will generate error if trying to access not existent objects property, one should check array value and not values property

Content

[...]
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.
[...]