【问题标题】:Cakephp before beforefilter过滤前的 Cakephp
【发布时间】: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


    【解决方案1】:

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

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

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

    所以我只是添加了一个空白的 find() 方法,它现在可以工作了。

    class FcStudentMilestoneComponent extends Object {
    
        function find(){
    
        }
    }
    

    非常困惑,但我会认为它已修复并暂时继续。但是一个解释会很棒!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      相关资源
      最近更新 更多