Home  >  Article  >  PHP Framework  >  Where is the yii error prompt location?

Where is the yii error prompt location?

藏色散人
藏色散人Original
2020-07-22 11:04:082366browse

The yii error prompt location is under the "@app/views/site/error.php" path, and the default error, the error prompt action, is handled by the error action under the site controller.

Where is the yii error prompt location?

Yii2 Modify the error prompt page style

yii2 The default error action is by default under the site controller error action to handle, the corresponding error view page is @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 from yii\web\ErrorAction Processing, by default the error view page error.php will inherit the layout file. We can modify the layout file of the error.php page by modifying the actions() method. At the same time, in order to set its error action for each controller, you can define a base The class BaseController inherits 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, yii \web\ErrorAction class takes over, layout specifies the error display page using the layout file, view the source code:

Return error message name (error name, such as 404), message (Simple information), exception (error object)

Recommended: "yii tutorial"

The above is the detailed content of Where is the yii error prompt location?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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