在beforeFilter中,我正在根據登錄的用戶爲我的默認視圖設置一個變量。這很有效,直到調用註銷操作爲止。beforefilter之前的CakePHP
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組件沒有用戶標識。我試過使用if($ this-> Auth-> user())或if($ this-> Auth-> user('id')),但仍然返回true並繼續嘗試執行查詢。
這裏是我得到的錯誤:Call to undefined method FcStudentMilestoneComponent::find()
我有在組件文件夾中的FcStudentMilestone組件文件,所以我真的認爲這是與缺乏一個用戶ID,但我可能是遙遠。
此外,已經注意到錯誤是指實際的查找語句,但我在前面調用當前用戶id,所以爲什麼它不標記該行而不是find語句的行?