Yii Framework Forum: Redirect User on not authorized - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Redirect User on not authorized Rate Topic: -----

#1 User is offline   thiagovidal 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 147
  • Joined: 17-February 10
  • Location:Brazil, São Paulo

Posted 24 June 2010 - 10:38 AM

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?
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 24 June 2010 - 11:39 AM

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');
    }

    ...
}

0

#3 User is offline   thiagovidal 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 147
  • Joined: 17-February 10
  • Location:Brazil, São Paulo

Posted 24 June 2010 - 12:14 PM

Still not working...
0

#4 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 24 June 2010 - 04:26 PM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users