如何在CodeIgniter中禁用PHP错误报告? [英] How to disable PHP Error reporting in CodeIgniter?
问题描述
我阅读了官方的文档,他们所说的都是我应该有一个 error_reporting()函数位于您的主index.php文件的顶部。但我没有在我的项目中的 index.php
文件。我的基本控制器叫 core
所以要获得主索引我去 www.mysite.dom / core /
。所以我想这个错误报告功能应该在这个控制器?然后我想知道的是,我应该把它放在控制器,什么放在里面禁用报告。谢谢大家的帮助,猜猜我缺少的东西:/
I've read the official documentation and all they say is that I should have a error_reporting() function located at the top of your main index.php file. But I don't have index.php
file in my project. My base controller is called core
so to get to main index I go to www.mysite.dom/core/
. So I guess this error reporting function should be inside this controller? Then what I would like to know is where should I put it in the controller and what to put inside of it to disable the reporting. Thank you all for help, guess I am missing something :/
推荐答案
这里是新的Codeigniter项目的典型结构: p>
Here is the typical structure of new Codeigniter project:
- application/
- system/
- user_guide/
- index.php <- this is the file you need to change
我通常在我的CI index.php中使用这个代码。只需将local_server_name更改为本地Web服务器的名称。
I usually use this code in my CI index.php. Just change local_server_name to the name of your local webserver.
使用此代码,您可以将每个站点部署到生产服务器,而不必每次都更改index.php。
With this code you can deploy your site to your production server without changing index.php each time.
// 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.');
}
}
这篇关于如何在CodeIgniter中禁用PHP错误报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!