开发者

How to configure Codeigniter to report all errors?

I had a line - $autoload['libraries'] = array('database');, in CI's autoload.php. 开发者_如何学CBecause of this I was getting a blank page. When I removed the 'database', option then I started getting the output.

Now my question is not how to configure the database, but how to configure CI to speak its mind. When 'database' was enabled all I got was a complete blank page. No error in php log, no error in Apache log, no error in CI log. In PHP I have set E_ALL. In my CI config I have set log_threshold to 4, i.e. all messages should be logged. What more do I need to do?


It depends on your version of CI. For < 2.x edit the top level index.php and adjust the error_reporting function to use E_ALL"

error_reporting(E_ALL);

For >= 2.x edit the top level index.php and make sure ENVIRONMENT is set as:

define('ENVIRONMENT', 'development');

which sets the error_reporting to E_ALL.


Create a .htaccess file in your webroot with the following content

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value error_reporting -1
php_value log_errors_max_len 0

Hopefully that should enable your logs.
Make sure to set the values to off and reporting to 0 on your production server :)


Following environment settings would gonna force PHP to display errors as they occur:

  • APPLICATION ENVIRONMENT define('ENVIRONMENT', 'development'); /*
  • ERROR REPORTING

    if (defined('ENVIRONMENT')) { switch (ENVIRONMENT) { case 'development': // Report all errors error_reporting(E_ALL);

            // Display errors in output
            ini_set('display_errors', 1);
            break;
    
        case 'testing':
        case 'production':
            // Report all errors except E_NOTICE
            // This is the default value set in php.ini
            error_reporting(E_ALL ^ E_NOTICE);
    
            // Don't display errors (they can still be logged)
            ini_set('display_errors', 0);
        break;
    
        default:
            exit('The application environment is not set correctly.');
    }
    

    }


I am not sure what was the real reason but I had a PHP installation with left-over php.ini file. Later I installed the full WAMP stack with its own PHP. When I deleted the leftover php.ini file from the previous installation then it started working as it should. It seems the PHP binaries in the new installing was using using the left-over php.ini which was in totally different directory; maybe because that directory was in environment PATH.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜