I have made my custom controller and set it as default in my main config file.

All the other actions are working fine. But when there is any error i have made :

 public function actionError() {
      echo 'Error'; die;
  } 

and then i made a not found request. It did not did the action written by me, but did default action.

Please suggest!!

有帮助吗?

解决方案

If you want to use your custom error action, you have to configure the errorAction in the errorHandler application component. You can do so in your main.php. If your controller is CustomController you'd configure:

'components' => array(
    // ...
    'errorHandler' => array(
        'errorAction' => 'custom/error',
    ),
    // ...

其他提示

You dont have to echo inside the controller.Create a view file inside your views folder and render it like so public function actionError(){ $this->render('viewName') }

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top