Domanda

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!!

È stato utile?

Soluzione

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',
    ),
    // ...

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top