Cakefp在beforefilter之前

时间:2011-01-12 14:52:59

标签: cakephp-1.3

在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语句的行?

1 个答案:

答案 0 :(得分:1)

所以,也许有人可以解释为什么这是一个修复,但是,

var $components = array('Acl', 'Auth', 'Session', 'FcStudentMilestone', 'FcSection');

当调用注销或登录操作时,FcStudentMilestone组件不继承find()方法。

所以我刚刚添加了一个空白的find()方法,现在可以了。

class FcStudentMilestoneComponent extends Object {

    function find(){

    }
}
极端困惑,但我只是认为它已修复并继续前进。但是解释会很棒!

相关问题