如何在执行过滤器之前执行身份验证

时间:2019-05-30 10:02:34

标签: php cakephp cakephp-2.0

我在Rest Api中构建了Cakephp,在App Controller中进行了一些配置,before filter在整个应用程序的数据库中存储了一些与登录用户有关的数据不仅用于json请求,而且在json请求的情况下为空,并且似乎在调用before filter之前调用了Authentication componentApi的控制器中,我致电

public function beforeFilter()
{
    parent::beforeFilter();
    $this->Auth->authenticate['Token'] = array(
        'fields' => array(
        ),
        'header' => 'AuthenticationToken',
        'scope' => array(
            'User.permission_api_login' => true,
        )
    );
}

应用程序控制器

public function beforeFilter()
{
    // some code + allow Basic Auth for json request
    $this->Requestlog->save(array(
        'user_id' => $this->Auth->user('id'),
        'controller' => $this->name,
        'action' => $this->request->params['action'],
        'is_mobile' => $this->request->is('mobile'),
        'is_ajax' => $this->request->is('ajax'),
        'is_json' => $this->_isJsonRequest(),
    ));
}

如何获取before filter中的用户数据?还是我该怎么办?

0 个答案:

没有答案