我在cakepp中有一些代码,它会产生一个错误。
这是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
这个错误是什么意思?
我在core.php中启用了调试模式:Configure::write('debug', 2);
,它解决了我的问题。
在我的情况下,调试模式是core.php中实时服务器上的Configure::write('debug', 0);
。
我将其设置为Configure::write('debug', 1);
,这次没有显示任何错误。
所以我再次将调试模式更改为Configure::write('debug', 0);
,因为我不想在我的实时站点上显示调试错误。
这一次没有显示错误消息。
所以只要在core.php中更改一次调试模式就可以在我的情况下消除这个错误。
如果您将调试模式更改为1,然后在本地运行更改后的函数,CakePHP将刷新这些函数中包含的所有模型的缓存。现在您可以更改回Configure::write('debug', 0)
。
不要在生产中设置Configure::write('debug',2)
,否则可能会在出现错误时向用户写入敏感数据(如Query),debug 2之所以有效,是因为CACHE中的项目不再被考虑,所以它有效。只需删除缓存并在生产中将调试保留为0非常重要
可以在这里找到缓存:tmp/cache/
再说一遍,不要删除你在那里找到的3个文件夹,只需删除它们的内容。