这是我在同一页面的控制器中的登录和注销功能。当我在注销时使用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']);
}
答案 0 :(得分:0)
假设您想使用与CakePHP 3默认的Users
模型不同的模型,您可以将其放在AuthComponent
的设置中。
// AppController.php -> initialize method
$this->Auth->config('authenticate', [
'Form' => ['userModel' => 'Members']
]);