【问题标题】:Cakephp Error: An internal error has occurredCakephp 错误:发生内部错误
【发布时间】:2013-11-30 17:08:55
【问题描述】:

我在 cakephp 中有一些代码会产生错误。

这是 PHP 控制器:

$this->loadModel( 'Vote' ); //Newly added by amit start
$vote=$this->Vote->getVote($id,$uid);
$this->set('vote',$vote);
$voteCount = count($vote);
$this->set('voteCount',$voteCount);

$voteShow = $this->Vote->find('all', array(
    'fields' => array('SUM(Vote.score)   AS score','count(id) as countId'),
     'conditions'=>array('Vote.type_id'=>$id),
));
$this->set('voteShow',$voteShow);

型号:

public function getVote($id,$uid) {
    if (empty($conditions))
        $conditions = array('Vote.type' => 'blog',
                            'Vote.type_id' => $id,
                            'Vote.user_id' => $uid);

    $users = $this->find('all', array('conditions' => $conditions,
        'order' => 'Vote.id desc'
    ));
    return $users;
}

该代码产生此错误:

Error : An internal error has occurred

这个错误是什么意思?

【问题讨论】:

    标签: cakephp internal-server-error


    【解决方案1】:

    我在 core.php 中启用了调试模式:Configure::write('debug', 2);,它解决了我的问题。

    【讨论】:

    • 请勿在生产环境中执行此操作,否则您可能最终会在出错时向用户写入敏感日期(例如查询),调试 2 起作用的原因是因为缓存中的项目是不再考虑,所以它有效。只需删除缓存并在生产中将 DEBUG 保留为 0 非常重要
    【解决方案2】:

    在我的情况下,调试模式是 Configure::write('debug', 0); 在 core.php 中的实时服务器上。

    我将它设置为Configure::write('debug', 1);,这次没有显示错误。

    所以我再次将调试模式更改为Configure::write('debug', 0);,因为我不想在我的实时站点上显示调试错误。

    这次没有出现错误信息。

    所以只需在 core.php 中更改一次调试模式就可以摆脱这个错误。

    如果您将调试模式更改为 1,然后在本地运行您已更改的函数,CakePHP 将刷新包含在这些函数中的所有模型的缓存。现在你可以改回Configure::write('debug', 0)

    【讨论】:

    • 看我上面的回答,你就会明白为什么当你把它设置为 1 时它会起作用!
    【解决方案3】:

    不要在生产中设置Configure::write('debug',2),否则你可能会在出错时将敏感数据(如Query)写入用户,调试2起作用的原因是因为CACHE中的项目没有被纳入不再考虑,所以它起作用了。只需删除缓存并在生产中将 DEBUG 保留为 0 非常重要

    可以在这里找到缓存:tmp/cache/

    再一次,不要删除你会在那里找到的 3 个文件夹,只需删除它们的内容。

    【讨论】:

      猜你喜欢
      • 2013-10-21
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 2018-10-31
      • 2017-06-24
      • 2018-11-30
      • 1970-01-01
      相关资源
      最近更新 更多