代码点火器+哎呀

Codeigniter + Whoops

我正在尝试设置 Whoops on a Codeigniter 3 应用程序。

我用 composer 安装了 Whoops 并这样调用它:

use Whoops\Handler\PrettyPageHandler;
if (ENVIRONMENT == 'development') {
    $whoops = new \Whoops\Run;
    $whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
    $whoops->register();

    $handler = new PrettyPageHandler;
    $handler->setEditor('sublime');
}

它适用于警告、通知和已弃用的错误,但不适用于致命错误。

CodeIgniter 似乎在糟糕之前处理了它们。有没有办法修改此行为?

我通过在我的 index.php 文件中移动 "Whoops Run" 使其工作,在定义我的开发环境和错误报告设置之后(在 CI [=17 中的第 70 行左右) =] 文件):

/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 * 2017-08-21: Adding Whoops profiler
 */
use Whoops\Handler\PrettyPageHandler;
switch (ENVIRONMENT)
{
    case 'development':
    case 'staging':
        error_reporting(-1);
        ini_set('display_errors', 1);
        error_reporting(E_ALL ^ E_WARNING ^ E_USER_WARNING ^ E_NOTICE ^ E_DEPRECATED );
        $whoops = new \Whoops\Run;
        $whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
        $whoops->register();
    break;

    case 'testing':
    case 'production':
        ini_set('display_errors', 0);
        if (version_compare(PHP_VERSION, '5.3', '>='))
        {
            error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
        }
        else
        {
            error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
        }
    break;

    default:
        header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
        echo 'The application environment is not set correctly.';
        exit(1); // EXIT_ERROR
}

this Github Whoops issue 中的一条评论告诉了我!