简体   繁体   中英

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 .

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.

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. It kinda weird thought to instance Whoops handler in to different places.

Reference: Codeigniter + Whoops

I got it working nicely by doing the following:

  1. Make sure hooks are enabled in config/config.php

     $config['enable_hooks'] = true; 
  2. Add a hook in 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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