【问题标题】:Using $this when not in object context while using destroy function使用销毁函数时不在对象上下文中使用 $this
【发布时间】:2016-10-19 10:14:17
【问题描述】:

这是我在同一页面控制器中的登录和注销功能。当我在注销中使用 Session::destroy() 时,它会抛出一个错误“不在对象上下文中使用 $this”。并告诉我如何检查会话是否处于活动状态。 提前谢谢你

public function login(){
       $session = $this->request->session();  
      $student12 = TableRegistry::get('users');    
         $email=$this->request->data('email');
         $password=$this->request->data('password');
          $query12 = $student12->find();
          $query12->where(['email'=>$email]);
        foreach($query12 as  $datax)
        {
        if($datax['password']===$password&&$datax['email']===$email)
        {   

//Session::write($key, $value);
//Session::read($key);
         $this->redirect(['controller'=>'Panal','action' => 'Home']);
        }else{
          $this->redirect(['controller'=>'Student','action' => 'index']);  
        }
    }
    }

    public function logout(){

      Session::destroy();
       $this->redirect(['controller'=>'Panal','action' => 'Home']);

    }

【问题讨论】:

标签: session cakephp cakephp-3.0


【解决方案1】:

假设你想使用不同于 CakePHP 3 默认的 Users 模型,你可以把它放在 AuthComponent 的设置中。

// AppController.php -> initialize method
$this->Auth->config('authenticate', [
    'Form' => ['userModel' => 'Members']
]);

RTFM 参考:http://book.cakephp.org/3.0/en/controllers/components/authentication.html#configuring-authentication-handlers

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 2015-02-12
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多