Heim > Fragen und Antworten > Hauptteil
Session::set('user_id',$user->id);
Session::set('user_info',$user->getData());
人生如戏2018-05-05 17:13:10
user.php
....
use think\Request;
use app\index\model\User as UserModel;
use think\Session;
....
public function checkLogin(Request $request)
{
//初始返回参数
$status = 0;
$result = '';
$data = $request -> param();
//创建验证规则
$rule = [
'name|用户名' =>'require',
'password|密码' => 'require',
'veritfy|验证码' =>'require|captcha',
];
//创建验证失败信息
$msg = [
'name' =>['require'=>'用户名不能为空,请检查'],
'password' =>['require'=>'密码不能为空,请检查'],
'veritfy' =>['require'=>'验证码不能为空,请检查',
'captcha'=>'验证码错误,请检查'
],
];
//进行简单验证
$result = $this -> validate($data,$rule,$msg);
//如果验证成功,则执行
if($result === true)
{
//构造查询条件
$map = [
'name'=>$data['name'],
'password'=>md5($data['password'])
];
//查询用户信息
$user = UserModel::get($map);
if($user == null){
$result = '没有找到该用户!';
}else{
$status = 1;
$result = '验证通过,点击[确定]进入!';
//设置用户的Session值
//Session::set('user_id',$user->id);//用户ID
// Session::set('user_info',$user->getData());//获取用户所有信息
Session::set('user_id,$user[id]');
Session::set('user_info.name',$user['name']);
}
}
return ['status'=>$status,'message'=>$result,'data'=>$data];
}
header.htnl
<li>超级管理员</li>
<li class="dropDown dropDown_hover"> <a href="#" class="dropDown_A">{:session('user_info.name')} <i class="Hui-iconfont"></i></a>
<ul class="dropDown-menu menu radius box-shadow">
<li><a href="{:url('user/logout')}">退出</a></li>