不使用CI的時候,我們可以使用 error_reporting(E_ALL); error_reporting(0); 這類的代碼來控制報錯級別。當然也可以在類中使用這些語句,不過CI自己已經有控制報錯級別的機制在裡面了。
也許你不會經常打開index.php,但是修改就在這個文件裡面:
/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
*---------------------------------------------------------------
*
* You can load different configurations depending on your
* current environment. Setting the environment also influences
* things like logging and error reporting.
*
* This can be set to anything, but default usage is:
*
* development
* testing
* production
*
* NOTE: If you change these, also change the error_reporting() code below
*
*/
define('ENVIRONMENT', 'development');
/*
*---------------------------------------------------------------
* 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.');
}
}
ENVIRONMENT 就是來控制報錯級別的,默認的有三個選項,development testing production,由上面的switch語句控制。代碼已經很清楚了,可以根據自己的需求進行相應更改。