Session::set('user_id',$user->id);
Session::set('user_info',$user->getData());
tp5.1 changed the reference path to: use think\Facade\Session;
Print it first to see if you can output the data you submitted and see if the data is correct
user.php
....
use think\Request;
use app\index\model\User as UserModel;
use think\Session;
public function checkLogin(Request $request)
{
//Initial return parameters
$status = 0;
$result = '';
$data = $request -> param();
//Create validation rules
$rule = [ ’ ’ ’ s ’ s ’ s ’ ’ ’ s ’ ’ s ’ ’ s ‐ ‐ ‐ ‐ ‐ ‐ to 'name|Username' => 'require',
##;
'veritfy' =>['require'=>'The verification code cannot be empty, please check',
'captcha'=>'Verification code error, please check'
$result = $this -> validate($data,$rule,$msg);
## ($ Result === True)
# {
// Construction query condition
$ map = [
# 'name' = & gt; $ data ['name'],
# 'Password' = & GT; md5 ($ data ['password']
$ User = Usermodel :: get ($ map);
$ result = 'No found! ';
}else{
$status = 1;
$result = 'Verification passed, click [OK] to enter!';
//设置用户的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>
Post all the code! !
tp5.1 changed the reference path to: use think\Facade\Session;
Print it first to see if you can output the data you submitted and see if the data is correct
user.php
....
use think\Request;
use app\index\model\User as UserModel;
use think\Session;
....
public function checkLogin(Request $request)
{
//Initial return parameters
$status = 0;
$result = '';
$data = $request -> param();
//Create validation rules
$rule = [ ’ ’ ’ s ’ s ’ s ’ ’ ’ s ’ ’ s ’ ’ s ‐ ‐ ‐ ‐ ‐ ‐ to 'name|Username' => 'require',
## ## 'Veritfy | Verification Code' = & GT; 'Require | CAPTCHA',##;
## // ## $ msg = [# 'name' = & gt; ['Require' = & gt; 'Username cannot be empty, please check'], 'password' = & gt; [[[[[[[[ 'require'=>'The password cannot be empty, please check'],'veritfy' =>['require'=>'The verification code cannot be empty, please check',
'captcha'=>'Verification code error, please check'
$result = $this -> validate($data,$rule,$msg);
## ($ Result === True)
# {
// Construction query condition
$ map = [
# 'name' = & gt; $ data ['name'],
# 'Password' = & GT; md5 ($ data ['password']
##] [[$ User = Usermodel :: get ($ map);
## counter ($ user == null) {$ result = 'No found! ';
}else{
$status = 1;
$result = 'Verification passed, click [OK] to enter!';
//设置用户的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>
Post all the code! !