原理
登录
验证成功后,将teacherId利用session存起来,实现了用户登录。
注销
直接将存在于session中的变量,销毁即可。
1.M层
application\common\model\teacher
/**
* 退出登录
* @return bool
*/
static public function logout()
{
//销毁session中数据
session('teacherId',null);
return true;
}
2.C层
\application\index\controller\LoginController.php
//退出
public function logout(){
if(Teacher::logout()){
return $this->success('退出成功',url('index'));
}else{
return $this->error('退出失败',url('index'));
}
}
效果:http://tp5/index.php/index/login/logout
退出成功