As far as I can tell, CHttpRequest "happens" before CUrlManager, so route information is not available in a proper fashion. Because this application uses certain CUrlManager settings that make URLs look like "controller/action", this works. There probably are nicer ways of doing this, but this might be useful to someone.
One such way would be instantiating a "temporary" CUrlManager for finding out the proper route, but that'd be hack-ish as well.
The component:
<?php
class HttpRequest extends CHttpRequest
{
public $noCsrfValidationRoutes = array();
protected function normalizeRequest()
{
parent::normalizeRequest();
$route = implode('/', array_slice(explode('/', Yii::app()->getUrlManager()->parseUrl($this)), 0, 2));
if($this->enableCsrfValidation && array_search($route, $this->noCsrfValidationRoutes) !== false)
Yii::app()->detachEventHandler('onbeginRequest',array($this,'validateCsrfToken'));
}
}
?>
The config snippet
...
'request'=>array(
'class'=>'HttpRequest',
'enableCsrfValidation'=>true,
'noCsrfValidationRoutes'=>array('some/route', 'some/otherroute'),
'enableCookieValidation'=>true,
),
...

Help















