Handle 403 Error

Hello everyone,

I am developing an application with separated user and admin modul. When i am logged in as a normal user, and i trying to access admin section i got an 403 error printed it on display.

How can i set a custom 403 access denied page to it?

In my config.php, it dosen’t handle 403 errors.


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



I got this error message


You are not authorized to perform this action. (/var/yii_base/framework/web/auth/CAccessControlFilter.php:182)

#0 /var/yii_base/framework/web/auth/CAccessControlFilter.php(145): CAccessControlFilter->accessDenied(Object(WebUser), ‘You are not aut…’)

#1 /var/yii_base/framework/web/filters/CFilter.php(38): CAccessControlFilter->preFilter(Object(CFilterChain))

#2 /var/yii_base/framework/web/CController.php(1145): CFilter->filter(Object(CFilterChain))

#3 /var/yii_base/framework/web/filters/CInlineFilter.php(58): CController->filterAccessControl(Object(CFilterChain))

#4 /var/yii_base/framework/web/filters/CFilterChain.php(130): CInlineFilter->filter(Object(CFilterChain))

#5 /var/yii_base/framework/web/CController.php(291): CFilterChain->run()

#6 /var/yii_base/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)

#7 /var/yii_base/framework/web/CWebApplication.php(282): CController->run(‘error’)

#8 /var/yii_base/framework/base/CErrorHandler.php(331): CWebApplication->runController(‘user/default/er…’)

#9 /var/yii_base/framework/base/CErrorHandler.php(204): CErrorHandler->render(‘error’, Array)

#10 /var/yii_base/framework/base/CErrorHandler.php(129): CErrorHandler->handleException(Object(CHttpException))

#11 /var/yii_base/framework/base/CApplication.php(732): CErrorHandler->handle(Object(CExceptionEvent))

#12 [internal function]: CApplication->handleException(Object(CHttpException))

#13 {main}

Thank you for your help in advance.

throw new CHttpException(403, ‘Your message here.’);

if you want custom error pages

  1. You need to take out errorHandler component



// delete this section in config/main.php


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




  1. Create a new directory under protected/views/system

  2. Create page for each error code like so "error404.php" and save it under system folder you just created

NOTE: you probably have to create pages for other codes as well otherwise its gonna render pages provided by Yii

Thank you for your answer. It works great!