我正在尝试在Whoops应用程序上设置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似乎先于Whoops处理它们。有没有办法修改此行为?

最佳答案

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

/*
 *---------------------------------------------------------------
 * 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中的一条评论提示了我!

关于php - Codeigniter +哎呀,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45786078/

10-13 05:03