简体   繁体   English

带有Whoops的CodeIgniter 3

[英]CodeIgniter 3 with Whoops

I can't get this working to any error occurred in CI entirely, Whoops registered as early as possible by adding handlers to index.php . 我无法完全解决CI中发生的任何错误,Whoops通过向index.php添加处理程序尽早注册。

switch (ENVIRONMENT)
{
    case 'development':
        error_reporting(-1);
        ini_set('display_errors', 1);
        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);

        $whoops = new \Whoops\Run;
        $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
        $whoops->register();

        throw new Exception("Whoops exception testing");

        break;

    case 'testing':

        break;

    case 'production':

        break;

    default:

        exit(1);
}

Whoops handle the error occurred in index.php file, but not when error happen in Controller or Model, it seems that CI error handler kinda catch the error first before Whoops does. Whoops处理在index.php文件中发生的错误,但是当Controller或Model中发生错误时却无法处理,看来CI错误处理程序在Whoops之前先捕获了错误。

Next attempt was to also register Whoops in MY_Controller.php construct, it works, but only Exception was handle by Whoops, a simple syntax error like forgetting semicolon still handle by CI error handler. 下一个尝试是也在MY_Controller.php构造中注册MY_Controller.php ,它可以工作,但是只有Exception由MY_Controller.php ,这是一个简单的语法错误,例如忘记分号仍由CI错误处理程序处理。 It kinda weird thought to instance Whoops handler in to different places. 将Whoops处理程序部署到不同的地方有点奇怪。

Reference: Codeigniter + Whoops 参考: Codeigniter +哎呀

I got it working nicely by doing the following: 通过执行以下操作,我使其运行良好:

  1. Make sure hooks are enabled in config/config.php 确保在config/config.php中启用了挂钩

     $config['enable_hooks'] = true; 
  2. Add a hook in config/hooks.php config/hooks.php添加一个钩子

     $hook['pre_system'][] = array( 'class' => 'WhoopsHook', 'function' => 'bootWhoops', 'filename' => 'WhoopsHook.php', 'filepath' => 'hooks', 'params' => array() ); 
  3. Create a new file hooks/WhoopsHook.php with the following code: 使用以下代码创建一个新的文件hooks/WhoopsHook.php

     <?php class WhoopsHook { public function bootWhoops() { $whoops = new \\Whoops\\Run; $whoops->pushHandler(new Whoops\\Handler\\PrettyPageHandler()); $whoops->register(); } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM