开发者

Cakephp before beforefilter

开发者 https://www.devze.com 2023-02-04 08:41 出处:网络
In the beforeFilter, I am setting a variable for my default view based on the user that is logged in... This works great until the logout action is called.

In the beforeFilter, I am setting a variable for my default view based on the user that is logged in... This works great until the logout action is called.

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']);  
 }
 re开发者_运维问答turn $arr;
}

I think most of that code is irrelevant but it's there anyway. What is happening is, when the user logs out it is still trying to perform the query after the logout is happening but the Auth component has no user id.

i have tried using the if($this->Auth->user()) or if($this->Auth->user('id')) but that is still returning true and proceeding to try and execute the query.

here is the error I am getting : Call to undefined method FcStudentMilestoneComponent::find()

I do have the FcStudentMilestone component file in the components folder so i really think it has something to do with the lack of a user id but i could be way off.

Also, have noticed that the error refers to the actual find statement, but I am calling the current user id in the line before, so why would it not flag that line instead of the line with the find statement?


So, maybe someone can explain why this is a fix but,

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

When the logout or login action is called, the FcStudentMilestone component is not inheriting the find() method.

So i just added a blank find() method and it now works.

class FcStudentMilestoneComponent extends Object {

    function find(){

    }
}

extremeley confused but I'll just consider it fixed and move on for now. But an explanation would be awesome!

0

精彩评论

暂无评论...
验证码 换一张
取 消