lucidtaz/yii2-whoops

Whoops错误处理器的Yii2绑定

dev-master 2019-02-06 14:57 UTC

This package is auto-updated.

Last update: 2024-09-07 05:15:52 UTC


README

此库提供将filp/whoops轻松集成到Yii2的功能。Whoops是一个非常漂亮的异常和错误格式化工具。此库允许您通过在应用程序配置中配置ErrorHandler来使用它。

用法

配置 web.php 以禁用Yii的内置错误处理器并使用新的错误处理器

<?php
$config = [
    // ...
    'components' => [
        'errorHandler' => [
            'class' => 'lucidtaz\yii2whoops\ErrorHandler',

            // NOTE: yii2-app-basic comes with this errorAction line by default,
            // be sure to comment/remove it, or you will get an
            // UnknownAttributeException when running your code:
            // 'errorAction' => 'site/error'
        ],
        // ...
    ],
    // ...
];

或者仅在使用Dev+Debug模式时使用,以防止在生产中显示源代码

<?php
$config = [
    // ...
    'components' => [
        'errorHandler' => YII_ENV_DEV && YII_DEBUG ? [
            'class' => 'lucidtaz\yii2whoops\ErrorHandler',
        ] : [
            'class' => 'yii\web\ErrorHandler',
            'errorAction' => 'site/error'
        ],
        // ...
    ],
    // ...
];