Custom Actionerror To Inherit From

Hello,

I’m currently trying to setup a custom actionError function for my api controllers. You can see my directory setup here.

Now I’ve created a ApiController.php in my Components folder with the following content:




class ApiController extends CController

{

    public function init()

    {

        parent::init();

        Yii::app()->errorHandler->errorAction = $this->actionError();

    }


    public function actionError()

    {

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

            echo CJSON::encode($error);

    }

}



In my api controllers I inherit from this class, e.g.:




class UserController extends ApiController



When throwing an exception the actionError function doesn’t get executed.

Any idea how I can fix that problem?

According to docs errorAction is just a string (route to handler), not a function.

I haven’t looked at the actual code yet, so I don’t know is there any way to use ref as a handler.