Error view not rendered when using useStrictParsing = true


We almost always use

'useStrictParsing' => true

In the urlManager component of our web apps.

However, this appears to be causing a problem rendering error views.

For example, if I set a URL rule:

'test/<id:\d+>' => 'site/test' // Looking for a numeric digit, eg /test/123

If I visit /test/999, our controller code attempts to load model ID 999 (which doesn’t exist) and throws a 404 exception:

throw new CHttpException(404, 'Not Found');

This then renders the error view via site/error as per the error config:

'errorHandler' => array(

    // use 'site/error' action to display errors

    'errorAction' => 'site/error',


So that’s all good - working as expected.

However, if I visit /test/abc - which does not contain a matching numerical digit, Yii does not render the error view and I see an unstyled browser error page with no layout or view.

If I try to exit() inside site/error - nothing happens, it’s like Yii isn’t even using the site/error method. However if I remove the site/error method, Yii throws an error saying it can’t find the method!

Any ideas how I can use ‘useStrictParsing’ => true and still get Yii to render proper error view 404’s on non-matching URLs?


you could register another route with ‘test/*’ map it to an action and throw an error in that action I know its hacky but it will do the job

Thanks alirz23, an interesting thought which led me to try a catch-all rule at the end of my urlManager rules:

'(.*)/?(.*)' => 'site/notFound',

public function actionNotFound()


    // Throw a 404, which then uses the site/error method properly

    throw new CHttpException(404, 'Page not found');


Which achieves the desired result.

It’s not the prettiest solution though, and I’d still like to know if there is a Yii way of doing it - and why using useStrictParsing=true breaks the site/error method.

Do you use accessControl filter in the SiteController?

If yes, please copy and paste the accessRules function content here.

Yeah we are using accessControl in the Site controller. The thought did occur to me that the actionError method might have been protected by the accessControl, but our rules are:

public function accessRules()


	return array(


			'actions'=>array('error', 'notFound'),



		array('deny',  // deny all users





So it should be ok?

I don’t think, you probably have to hack the core, error occurs before you even get to the controller, so you can mess with accessControl filter all you want