我读过官方的documentation,他们说我应该在你的主index.php文件的顶部有一个error_reporting()函数。,但是我的项目中没有index.php
文件。我的基本控制器叫做core
,所以为了获得主索引,我转到了www.mysite.dom/core/
。所以我猜这个错误报告函数应该在这个控制器内部?然后我想知道的是我应该把它放在控制器的什么地方,以及在里面放什么来禁用报告。谢谢大家的帮助,我想我漏掉了一些东西:/
发布于 2013-12-25 22:33:48
下面是新Codeigniter项目的典型结构:
- application/
- system/
- user_guide/
- index.php <- this is the file you need to change
我通常在CI index.php中使用此代码。只需将local_server_name更改为本地the服务器的名称即可。
使用此代码,您可以将站点部署到生产服务器上,而无需每次更改index.php。
// Domain-based environment
if ($_SERVER['SERVER_NAME'] == 'local_server_name') {
define('ENVIRONMENT', 'development');
} else {
define('ENVIRONMENT', 'production');
}
/*
*---------------------------------------------------------------
* 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);
ini_set('display_errors', 0);
break;
default:
exit('The application environment is not set correctly.');
}
}
发布于 2017-04-19 02:25:37
将CI index.php文件更改为:
if ($_SERVER['SERVER_NAME'] == 'local_server_name') {
define('ENVIRONMENT', 'development');
} else {
define('ENVIRONMENT', 'production');
}
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.');
}
}
如果关闭了PHP错误,但仍然会显示任何MySQL错误,请在/config/database.php文件中关闭这些错误。将db_debug选项设置为false:
$db['default']['db_debug'] = FALSE;
此外,您还可以使用active_group作为开发,并使用production来匹配环境https://www.codeigniter.com/user_guide/database/configuration.html
$active_group = 'development';
$db['development']['hostname'] = 'localhost';
$db['development']['username'] = '---';
$db['development']['password'] = '---';
$db['development']['database'] = '---';
$db['development']['dbdriver'] = 'mysql';
$db['development']['dbprefix'] = '';
$db['development']['pconnect'] = TRUE;
$db['development']['db_debug'] = TRUE;
$db['development']['cache_on'] = FALSE;
$db['development']['cachedir'] = '';
$db['development']['char_set'] = 'utf8';
$db['development']['dbcollat'] = 'utf8_general_ci';
$db['development']['swap_pre'] = '';
$db['development']['autoinit'] = TRUE;
$db['development']['stricton'] = FALSE;
$db['production']['hostname'] = 'localhost';
$db['production']['username'] = '---';
$db['production']['password'] = '---';
$db['production']['database'] = '---';
$db['production']['dbdriver'] = 'mysql';
$db['production']['dbprefix'] = '';
$db['production']['pconnect'] = TRUE;
$db['production']['db_debug'] = FALSE;
$db['production']['cache_on'] = FALSE;
$db['production']['cachedir'] = '';
$db['production']['char_set'] = 'utf8';
$db['production']['dbcollat'] = 'utf8_general_ci';
$db['production']['swap_pre'] = '';
$db['production']['autoinit'] = TRUE;
$db['production']['stricton'] = FALSE;
发布于 2021-03-25 15:51:58
我知道我来晚了,但你可以这样做:在index.php文件中找到下面的代码
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
并将开发替换为production
https://stackoverflow.com/questions/20773786
复制相似问题