<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                用法一:控制器中自定義驗證 ``` //驗證規則 $rule = [ 'title|標題'=>'require', 'keys|關鍵字'=>'require', 'content|內容'=>'require', ]; //$data是需要驗證的數據 $row = $this->validate($data,$rule); //驗證不通過,返回錯誤信息 if ($row !==true){ $this->error($row); } ``` 用法二:場景驗證:在app目錄下建一個validate文件夾,再建一個類文件(文件名和模型一致) ``` 1.驗證類文件: namespace app\validate; use think\Validate; //繼承驗證類 class User extends Validate { //定義驗證規則 protected $rule = [ 'username|用戶名'=>'require|min:1|max:20', 'password|密碼'=>'require|length:6,12', 'repassword|確認密碼'=>'require|confirm:password', 'email|郵箱'=>'require|email', 'code|驗證碼'=>'require|captcha', ]; //中文提示消息,unique:判斷這個字段是否存在重復 protected $message = [ 'username.unique' => '用戶名已存在', 'email.uinque' => '郵箱已經存在', 'password.length:6,20' => '密碼必須在6到20位', ]; // 注冊驗證場景定義,scene+場景名 public function sceneAdd(){ return $this->only(['username','password','repassword','email'])->append('username','unique:user')->append('email','unique:user'); } // 登錄驗證場景定義 public function sceneLogin() { return $this->only(['username', 'password', 'code']); } public function sceneEdit() { return $this->only(['username','email'])->append('password','length:6,20'); } public function sceneForget() { return $this->only(["email","password","repassword"]); } } 2.在控制器中使用 先引入:use app\validate\User as UserValidate; // 實例化驗證器 $validate = new UserValidate(); // 判斷驗證失敗返回錯誤信息,使用添加場景edit驗證 if (!$validate->scene("edit")->check($data)){ $msg = $validate->getError(); $this->error($msg); } ```
                  <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>

                              哎呀哎呀视频在线观看