如何在 CodeIgniter 中禁用 PHP 错误报告? [英] How to disable PHP Error reporting in CodeIgniter?

查看:25
本文介绍了如何在 CodeIgniter 中禁用 PHP 错误报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了官方文档,他们只是说我应该有一个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 项目的典型结构:

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 更改为您本地网络服务器的名称.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆