The answer is that you never ever ever show PHP errors on a production server. You should only show them on your live server.
Therefore, while you are testing and building your application, it doesnt matter where the error shows up.
But on your live server, you need to hide the php error, whilst still logging. Codeignitier provides this ability.
Firstly, in your index.php change
define('ENVIRONMENT', 'development');
to
if ($_SERVER['SERVER_NAME'] == 'localhost')
{
define('ENVIRONMENT', 'development');
}
else
{
define('ENVIRONMENT', 'production');
}
this will automatically set Development mode for when you are on your localhost, and production mode when it is deployed (i.e. no code changes).
Now you configure a few things as needed:
inside Index.php also change the error reporting to:
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(-1);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
Config.php
// Set logs to show Debug + Error messages on your development
// But only error messages on your production server
$config['log_threshold'] = (ENVIRONMENT == 'development' ? '2' : '1');
Database.php (config)
$active_record = TRUE;
$active_group = (ENVIRONMENT == 'development' ? 'localdev' : 'production');
// Now define the two different groups here, making sure production has:
$db['production']['db_debug'] = FALSE;