【问题标题】:CodeIgniter Helper function ignores all errors, output and even die()CodeIgniter Helper 函数忽略所有错误、输出甚至 die()
【发布时间】:2018-04-11 07:59:10
【问题描述】:

我是 CodeIgniter 的新手,但对 Symfony 等 MVC 框架非常熟悉。

我正在更改自定义帮助函数,我正在从数据库中检索数据。我认为数据库检索不起作用,但我没有收到任何错误。辅助函数只是忽略错误。日志文件中没有错误(log_threshold = 4),并且 die() 也被忽略了。

我将在下面发布辅助函数,但我的问题不是我的代码有什么问题(如果有的话),问题是为什么错误和 die() 被忽略了,我能做些什么来解决这个问题?

function getRates() {
$ci=& get_instance();
$ci->load->database();

$ci->db->select('currency_values.*');
$ci->db->from('version1.currency_values');
$currencyValues = $ci->db->get();

$lastUpdated = strtotime($currencyValues->result()[0]->last_updated);
die(">>> $lastUpdated <<<"); //This gets ignored

if ($lastUpdated > time() - 600)
{
    //Code here that SHOULD be running
}
else
{
    //Code here that ALWAYS runs, most likely because db retrieval is not working
}

【问题讨论】:

  • 您确定包含该函数的帮助文件已加载吗?

标签: php codeigniter helpers


【解决方案1】:

尝试使用try和catch并打印异常错误

try
{

}
catch(Exception $e){
echo $e;
}

【讨论】:

  • 辅助函数是否可能被缓存并且我所做的更改未被处理?如果是这样,我该如何刷新它?
  • 不,这似乎不太合理
【解决方案2】:

PHP 不可能忽略 die() 调用。通过放置几个 dummy 来确认它: echo "1\n"; 在多个地方或通过 使用exit() 而不是die()。虽然完全猜测,但解释器可能正在从其他地方读取代码。这种情况如果不是那么罕见。

为了不报错,数据库检索失败,可以使用PHP异常处理或设置error_reportingE_ALL

error_reporting(E_ALL); ini_set('display_errors', 1);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    相关资源
    最近更新 更多