我试图在Whoops应用上设置Codeigniter 3。
我用作曲家安装了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之前处理它们。有没有办法修改这种行为?
答案 0 :(得分:2)
在定义我的开发环境和错误报告设置(在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中的评论让我感到惊讶!