Codeigniter Error Reporting – Intelligent Fix
Description:
This little fix will help you to manage the error reporting automatically that if you ever will go online so error reporting will be disabled and when you will import you database in localhost and development phase will be continued so no headache of changing this ENVIRONMENT constant accordingly. By this automatic setting you can save your time and also prevent the unexpected situation where you can forget changing this constant before going online or again working offline.
Target File: index.php (Codeigniter Root Directory)
if(in_array($_SERVER[‘HTTP_HOST’],array(‘localhost’)))
{
define(‘ENVIRONMENT’, ‘development’); // 15-06-2012
}
else
{
define(‘ENVIRONMENT’, ‘production’); // 15-06-2012
}
/*
*—————————————————————
* ERROR REPORTING
*—————————————————————
*
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.
*/
if (defined(‘ENVIRONMENT’))
{
switch (ENVIRONMENT)
{
case ‘development’:
error_reporting(E_ALL);
break;
case ‘testing’:
case ‘production’:
error_reporting(0);
break;
default:
exit(‘The application environment is not set correctly.’);
}
}
Thanks,
Fahad
Last updated: March 19, 2014