亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

登錄模塊的實(shí)現(xiàn)

original 2019-05-14 11:43:10 348
abstrait:通過(guò)本章的學(xué)習(xí),實(shí)現(xiàn)了登錄模塊,控制器代碼如下:<?php namespace app\admin\controller; use app\admin\model\user\UserModel; use think\Controller; use think\facade\Request; use think\facade\Sessio

通過(guò)本章的學(xué)習(xí),實(shí)現(xiàn)了登錄模塊,控制器代碼如下:

<?php

namespace app\admin\controller;


use app\admin\model\user\UserModel;
use think\Controller;
use think\facade\Request;
use think\facade\Session;

class Login extends Controller
{
    public  function  Login()
    {
        return $this->view->fetch();
    }

    public  function  doLogin()
    {
        $data = Request::param();
        $res= UserModel::where('username', $data['username'])->find();
        if(!$res)
        {
            return ['res'=>'0','msg'=>'用戶名不存在'];
        }

        if($data['password']==$res->password)
        {
            Session::set('user',$res);

            return ['res'=>'1','msg'=>'登錄成功'];
        }else
        {
            return ['res'=>'0','msg'=>'用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入'];
        }

    }
}

通過(guò)新增公共控制器類(lèi)檢驗(yàn)用戶是否登錄:

<?php

namespace app\admin\controller;


use think\App;
use think\Controller;
use think\facade\Session;

class Check extends Controller
{
    public function __construct(App $app = null)
    {
        parent::__construct($app);

        if(!Session::has('user'))
        {
            $this->error('您還未登錄,請(qǐng)先登錄','Login/Login');
        }


    }
}

效果圖:

QQ截圖20190514114208.png

QQ截圖20190514114200.png

Professeur correcteur:天蓬老師Temps de correction:2019-05-14 17:49:44
Résumé du professeur:如果你用了模型, 就盡可能使用模型中的靜態(tài)方法, 例如get來(lái)代替:$res= UserModel::where('username', $data['username'])->find();

Notes de version

Entrées populaires