【发布时间】:2011-01-12 14:52:58
【问题描述】:
在 beforeFilter 中,我根据登录的用户为我的默认视图设置了一个变量...这在调用注销操作之前非常有效。
class AppController extends Controller {
var $components = array('Acl', 'Auth', 'Session', 'FcStudentMilestone', 'FcSection');
function beforeFilter(){
$this->set('completed_data', $this->_completedData());
}
function _completedData(){
$arr = array();
$x = strval($this->Auth->user('id'));
$compData = $this->FcStudentMilestone->find('all',
array('conditions' => array(
'FcStudentMilestone.user_id' => $x,
'FcStudentMilestone.completed' => '1')));
foreach ($compData as $compDatum) {
$compString = $this->FcSection->find('all',
array('conditions' =>
array('FcSection.id' =>
$compDatum['FcStudentMilestone']['fc_section_id'])));
array_push($arr, $compString[0]['FcSection']['name']);
}
return $arr;
}
我认为大部分代码是无关紧要的,但它仍然存在。发生的情况是,当用户注销时,它仍在尝试在注销后执行查询,但 Auth 组件没有用户 ID。
我尝试过使用 if($this->Auth->user()) 或 if($this->Auth->user('id')) 但这仍然返回 true 并继续尝试执行查询。
这是我得到的错误:Call to undefined method FcStudentMilestoneComponent::find()
我在 components 文件夹中确实有 FcStudentMilestone 组件文件,所以我真的认为这与缺少用户 ID 有关,但我可能会离题。
另外,已经注意到错误是指实际的 find 语句,但是我在之前的行中调用了当前用户 id,那么为什么它不标记该行而不是带有 find 语句的行呢?
【问题讨论】:
标签: cakephp-1.3