<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ## 說明 >[info]#### 模型,主要是對數據庫進行操作,進行增刪改查,是用來處理數據,邏輯處理的。 在用戶登錄當中,只用到了一個模型類,我們在 ```application\index\model``` 文件夾下面,新建一個名為```User.php``` 的文件,```User```與數據庫里的```tp_user```是一一對應的,如圖所示: ![](https://box.kancloud.cn/1f806842a3366b47ad6d48c5a8053436_386x316.png) ```Use.php```模型類文件里面的內容如下: ``` <?php /** * User: ye21st * Email: ye21st@gmail.com * Date: 2018/1/17 * Time: 10:30 */ namespace app\index\model; use app\index\controller\ResultCode; use think\Model; use think\facade\Session; /** * User 模型類 * Class User * @package app\index\model */ class User extends Model { /** * 登錄操作 * @param $username $string 用戶名 * @param $password $password 密碼 * @return int $code 返回碼 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function login($username,$password){ $userData = User::where('username','eq',$username) ->find(); // 如果查找到數據 if ( $userData ){ // 獲取該用戶信息對應的鹽值 $salt = $userData['salt']; // 將密碼進行 MD5 加密,將其與數據庫中的密碼字符串作對比,看看匹不匹配 $newPassword = md5($password.$salt); if ( $userData['password'] == $newPassword ){ // 獲得用戶所在ID $id = $userData['id']; // 設置session,用于首頁訪問,不存在,則返回到登錄頁面 Session::set('id',$id); Session::set('name',$username); return ResultCode::$LOGIN_SUCCESS; }else{ return ResultCode::$PASSWORD_ERROR; // 密碼錯誤 } }else{ return ResultCode::$USER_DOES_NOT_EXIST; // 該用戶不存在 } } } ``` >[info] 至此,關于用戶登錄,數據處理,邏輯處理部分,就做完了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看