yii2 default error action is handled by the error action under the site controller by default, and the corresponding error view page is the @app/views/site/error.php page.
return [ ....其它配置 'components' => [ ...其它配置 'errorHandler' => [ 'errorAction' => 'site/error', ], ] ]
The actions() method is rewritten in siteController, and the specified error action is handled by yii\web\ErrorAction. By default, the error view page error.php will inherit the layout file. We can modify the actions() method To modify the layout file of the error.php page.
At the same time, in order to set its error action for each controller, you can define a base class BaseController to inherit yii\web\Controller, and then other controllers inherit the base class and override the actions method in the base class. As follows:
public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', 'layout' => false, ], ]; }
class specifies the class that handles error information. When an error action occurs, the yii\web\ErrorAction class takes over. layout specifies the use of layout files for the error display page. View the source code:
Return error message name (error report name, such as 404), message (simple message), exception (error object)
Recommended related article tutorials: yii Framework tutorial
The above is the detailed content of How to modify the error page style in yii2. For more information, please follow other related articles on the PHP Chinese website!