php - 在 Codeigniter 中抑制特定请求的所有错误

标签 php debugging codeigniter

我正在开发一个 JSON 集成的 Web 应用程序,当我在(通过 ajax)页面请求的服务器端收到一些(一些有意的)PHP 错误时,在客户端进行调试真的很烦人。出于调试目的,我想仅针对此特定页面/ View / Controller 禁用所有与 PHP 和 DB 相关的错误的调试。

我已经尝试将以下内容放在我的 Controller 的顶部,根据我在互联网上找到的一些文章,它应该可以正常工作:

function index() {
    ini_set('display_errors', 0);
    $this->config->set_item('log_threshold', 0);

尽管如此,这仍然给我带来了该死的错误。

我知道我要求禁用这些错误听起来很愚蠢,但是……请相信我。

最佳答案

您是否在 index.php 中将 ENVIRONMENT 常量更改为“production”?
它将关闭所有错误

In production environments, it is typically desirable to disable PHP's error reporting by setting the internal error_reporting flag to a value of 0. This disables native PHP errors from being rendered as output, which may potentially contain sensitive information.

Setting CodeIgniter's ENVIRONMENT constant in index.php to a value of 'production' will turn off these errors. In development mode, it is recommended that a value of 'development' is used. More information about differentiating between environments can be found on the Handling Environments page.



如果没有帮助 - 尝试更新 CodeIgniter。

顺便说一下,这
$this->config->set_item('log_threshold', 0);

只是文件记录。

如果你只需要在一页上关闭试试这个
ini_set('display_errors', 'Off');
error_reporting(0);
define('MP_DB_DEBUG', false); 

关于php - 在 Codeigniter 中抑制特定请求的所有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11460658/

相关文章:

php - MySQL 插入日期日志

c++ - 是否有一个简单的 Windows 内存调试器(a)是免费的并且(b)可以工作?

php - 循环 DATETIME 并在 DATETIME 内保留 DATES

php - 如何在 CodeIgniter 中加载带有 View 的 css 文件?

php - 在表单上提交发送电子邮件+打开弹出窗口

php - 是休息; die() php 之后需要

Python 方法奇怪地暂停,直到 tkinter root 关闭

php - "php -a"交互式 shell 中的 xdebug

php - 无法将变量 'sql_mode' 设置为“REPLACE”的值

php - 使用 PHP exec() 在后台 Linux 服务器中运行脚本