Answer the question
In order to leave comments, you need to log in
How to display error page in YII2 controller?
As you know, by default, errors are handled in the error action of the site controller:
'components' => [
'errorHandler' => [
'errorAction' => 'site/error',
],
...
Answer the question
In order to leave comments, you need to log in
And what prevents you from looking at which controller in the 'site/error' action and calling this or that view or this or that algorithm already there?
or like this
class ApiController extends Controller {
public function init() {
parent::init();
Yii::app()->errorHandler->errorAction='api/error';
}
public function actionError(){
echo json_encode(array(
'Status'=>500,
'Message'=>'Unknown error'
));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question