Determine, Which Controller/action Caused An Error?

Is there any way to do that, what I’m asking in the title?

Checking Yii::app()->controller->id is useless (I think), as at the time of calling actionError this is already set to controller that holds actionError and I don’t know the way to determine controller, which action actually caused an error.

I have some controllers in main application context and some in modules. Controllers in modules acts as backend, available only to logged in users, while main application controllers are for general use – fronted). Both frontend and backend differs significantly in layout and general look & feel.

How can I determine which controller (backend / frontend) caused an error to display error message in proper context – that is either in backend or frontend (in some module or in main application body)?

Currenlty, I have one actionError declared in my main controller in main application context and added to app’s configuration and I have to decide if all errors will be displayed using frontend or backend layout (and code). This is something wrong, I would like to clearly separate these and display errors respectively.

Checking, if user is logged in also isn’t best idea, because when logged-in user will be browsing main page (frontend) and cause an error, it should see it in frontend layout, not in backend one.

Does anyone have any idea, how to achieve this?

Hi Trejder

Maybe is a tricky way but it works!

In your combonents/Controller.php override the beforeAction

protected function beforeAction($event) {

        if ($event->id != 'error') {

            Yii::app()->user->setState('originalController', $this->id);

            Yii::app()->user->setState('originalAction', $event->id);


        return true;


In your error file you know the controller/action that raise the error event




Tricky, but does look as a great idea! :] Thanks (+1)! :]