In config.php
I have
'urlManager'=>array(
'class'=>'UrlManager',
...
In UrlManager.php
I have
class UrlManager extends CUrlManager
{
public function parseUrl($request)
{
...
setcookie(microtime(true),date('H:i:s'),strtotime('+10 minutes'));
return parent::parseUrl($request);
}
}
When I try open page I see two cookies was produced by setcookie(microtime(true),date('H:i:s'),strtotime('+10 minutes'));
I expect there is would be just one cookie.
492786392.9662 17%3A53%3A12 // first cookie
1492786392.9704 17%3A53%3A12 // second cookie
It means method parseUrl
runs twice. But why? Is it normal behavior or can I avoid it?
I found just this topic http://www.yiiframework.com/forum/index.php/topic/3558-url-manager-causes-page-to-load-twice/ but without desicion.
Update 1.
I added var_dump('_',Yii::app()->request);
and noticed that
first output has
private '_cookies' (CHttpRequest) => null
as second output has
object(HttpRequest)[2982]
...
object(CCookieCollection)[3044]
private '_request' =>
&object(HttpRequest)[2982]
private '_initialized' => boolean true
private '_d' (CMap) =>
array (size=1)
'YII_CSRF_TOKEN' =>
object(CHttpCookie)[3043]
public 'name' => string 'YII_CSRF_TOKEN' (length=14)
public 'value' => string 'b78823914a0bb40b65093636b55687e683cf289f' (length=40)
public 'domain' => string '' (length=0)
public 'expire' => int 0
public 'path' => string '/' (length=1)
public 'secure' => boolean false
public 'httpOnly' => boolean false
private '_e' (CComponent) => null
private '_m' (CComponent) => null
private '_r' (CMap) => boolean false
private '_e' (CComponent) => null
private '_m' (CComponent) => null