How to prevent CI from reporting PHP Notice errors |
I don't have much experience with CI, but I have inherited a project that uses it.
As the title says, how do you prevent CI from reporting PHP notice errors? In the index.php file there's the following; PHP Code: switch (ENVIRONMENT) {
@shepparddigital,
What version of CI is it? If it is 3.x then here is the documentation: https://codeigniter.com/user_guide/gener...r-handling - in your switch case for 'production' add this statement: error_reporting(0);
Yes, it's 3.x, I've followed the documentation, and you can clearly see that on the 'development' environment I've changed the log level via error_reporting() to display all errors except notices, strict errors and user notices, but for one reason or another CI is still outputting those errors.
In the file application/config.php I have also set $config['log_threshold'] = 1; Why is CI still outputting notices? What am I missing? (07-04-2019, 02:06 AM)shepparddigital Wrote: Yes, it's 3.x, I've followed the documentation, and you can clearly see that on the 'development' environment I've changed the log level via error_reporting() to display all errors except notices, strict errors and user notices, but for one reason or another CI is still outputting those errors. Very strange! I tested on my server and it works... 1. perhaps'a you may have an overlaod controller for Exceptions (search under application/core) 2. maybe you have a try-catch-finally block on your own controller 3. be sure the CI code is clean: you must have in line 612 (system/core/Common.php): PHP Code: if (($severity & error_reporting()) !== $severity) can you post the controller source code that has this problem
if (defined('ENVIRONMENT'))
{ switch (ENVIRONMENT) { case 'development': case 'testing': case 'staging': error_reporting(E_ALL & ~E_NOTICE); break; case 'production': error_reporting(0); break; default: exit('The application environment is not set correctly.'); } } See the official PHP Documentation about the error_reporting function for more configuration options. Alternatively, you can just call the error_reporting function in the particular file you're using (whatever your cron job calls) and it'll overwrite the configuration with what you set in index.php. Here's a simple example using a controller: class Sample_Controller extends CI_Controller { public function __construct() { parent::__construct(); error_reporting(E_ALL & ~E_NOTICE); } } *SEO SPAM REDACTED**
You can set the environment in your .htaccess file that resides with index.php
Add to the top of it: Code: # Multiple Environment config, set this to development, testing or production What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
SetEnv is an Apache thing, so if your server is NGINX or other http server you will need to find the way your setup works with environmental variables.
If you are using Apache but following @InsiteFX's advice does not work then check that Apache has the env_module is enabled. |
Welcome Guest, Not a member yet? Register Sign In |