Chttpexception Without Styles And Layout After Login

hi all,

I’m trying to configure RBAC on my backend but CHttpException (403) appears without layout and styles, just plaintext on screen when user role is different from Admin. Here’s part of accessRules in AdminController (all Admin Pannel controllers extends base AdminController):


...

array('allow',

    'users'=>array('@'),

    'roles' => array('admin'),

),

...

The error action is in AdminController and it was generated by Gii without any changes.

Ok in your config file you should have something like this in the "compenents" section …




'errorHandler'=>array(

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

        'errorAction'=>'site/error',

),



Now when an error occurs your app will use the controller and action specified in the errorAction.

Now just use it like any other action …




public function actionError() {

			

	$this->layout = "my-layout";

	$this->render("error");

			

}



You can get the error message generated by Yii in the action method by doing …




Yii::app()->errorHandler->error["message"]



thanks for your reply

I have decided this problem by myself and our methods as it turned out are the same.

By default I have standard errorAction ‘core/default/error’. In protected/modules/core/views/layouts I made error.php layout which handles all system Exceptions. Finally I changed actionError in CoreController like this:


    public function actionError() {

        if ($error = Yii::app()->errorHandler->error) {

            if (Yii::app()->request->isAjaxRequest) {

                echo $error['message'];

            } else {                

                $this->layout = 'core.views.layouts.eror'; // layout for frontend and backend Exceptions 

                $this->render('error', $error);

            }

        }

    } 

Glad you have fixed it.