How to configure Codeigniter to report all errors?
Asked Answered
D

4

14

I had a line - $autoload['libraries'] = array('database');, in CI's autoload.php. Because 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?

Dander answered 10/9, 2011 at 7:52 Comment(5)
Could you give the output of phpinfo() inside of your CI-Program? What does trigger_error('test', E_USER_NOTICE) give you?Christenson
@Christenson Can you please let me know the exact section of phpinfo you want since, it outputs a really long list which I think cannot be posted here. BTW the output the tigger_error is A PHP Error was encountered, Severity: User Notice, Message: test, Filename: controllers/welcome.php, Line Number: 22. This came up in the browser window. In CI logs too it was logged as ERROR - 2011-09-10 13:49:21 --> Severity: User Notice --> test C:\....\lib\codeigniter\application\aceinvite\controllers\welcome.php 22.Dander
I just wanted to make sure, that the error-settings are correct (which is proven by the trigger_error). It may be possible, that the autoloader does not throw any error messages or exceptions. You could still get lucky defining your own error handler, but I guess it will not help. Maybe someone else has an idea (beside debugging the autoload.php that is) - good luck! :)Christenson
This helped me, try it: #9587913Entourage
I found this solution: #9587913 It worked for me.Entourage
T
16

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.

Tallith answered 10/9, 2011 at 10:16 Comment(2)
I am using >= 2.x version and define('ENVIRONMENT', 'development'); is already defined at the top of index.php.Dander
Accepting your answer since your answer is short and concise, even though my issue was something unrelated. Your answer is what 90% people would be looking for. For people who are still facing issue, they may want to look at my answer.Dander
P
12

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 :)

Piggish answered 11/9, 2011 at 8:20 Comment(0)
R
2

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.');
    }
    

    }

Reamy answered 20/9, 2019 at 0:46 Comment(1)
I am glad it worked for me in Codeignitor, would it work for all PHP frameworks or are there any limitations which bounds it to work for all PHP frameworks?Isleen
D
1

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.

Dander answered 11/9, 2011 at 18:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.