Redirect User on not authorized

How can I redirect the user whe he is not authorized to perform the action?

On some cases he will se the error page others he will see this

CHttpException

You are not authorized to perform this action. (E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\web\auth\CAccessControlFilter.php:153)

#0 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\web\auth\CAccessControlFilter.php(115): CAccessControlFilter->accessDenied(Object(WebUser), ‘You are not aut…’)

#1 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\web\filters\CFilter.php(39): CAccessControlFilter->preFilter(Object(CFilterChain))

#2 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\web\CController.php(999): CFilter->filter(Object(CFilterChain))

#3 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#4 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\web\filters\CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))

#5 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\web\CController.php(283): CFilterChain->run()

#6 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\web\CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)

#7 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\web\CWebApplication.php(320): CController->run(‘error’)

#8 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\base\CErrorHandler.php(235): CWebApplication->runController(‘site/error’)

#9 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\base\CErrorHandler.php(153): CErrorHandler->render(‘error’, Array)

#10 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\base\CErrorHandler.php(96): CErrorHandler->handleException(Object(CHttpException))

#11 E:\Users\thiagovidal\Development\xampp\htdocs\yii\framework\base\CApplication.php(581): CErrorHandler->handle(Object(CExceptionEvent))

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

#13 {main}

how can i redirect him to another page?

CAccessControlFilter throws CHttpException with error code "403" when an access is denied. If your errorHandler is configured that errorAction is "site/index", then you can modify SiteController as follows:




class SiteController extends CController

{

    ...

    

    public function actionError()

    {        

        if (Yii::app()->errorHandler->error['code'] == 403)

            $this->redirect('url');

        else

            $this->render('error');

    }


    ...

}



Still not working…

Did you add to your config file next strings?




'components'=>array(

    ...

    'errorHandler'=>array(

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

        'errorAction'=>'site/error',

    ),

    ...

),



It works for me.