Home > PHP Framework > YII > How to modify the error page style in yii2

How to modify the error page style in yii2

Release: 2019-12-14 11:22:02
Original
2752 people have browsed it

How to modify the error page style in yii2

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',
         ],
    ]
]
Copy after login

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,
            ],
        ];
    }
Copy after login

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:

How to modify the error page style in yii2

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template