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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                >[danger] 本篇內容非常重要,務必加深理解! [TOC] ### 后端代碼 ~~~ public $enableCsrfValidation = false; public function actionCreate() { if (Yii::$app->request->isPost) { $name = $_POST['name']; $city = $_POST['city']; $province = $_POST['province']; # 寫INSERT語句或使用下面的對象操作方法 $model = new Restaurant(); $model->name = $name; $model->city = $city; $model->province = $province; $model->save(); return $this->redirect('index'); } return $this->render('create'); } ~~~ ### 后端驗證 >[info] 驗證要求:三個字段均不為空,且餐館名稱不能大于5個漢字。 **更改數據庫字段類型** ~~~ $this->alterColumn('restaurant', 'name', $this->string(5)->notNull()); $this->alterColumn('restaurant', 'city', $this->string()->notNull()); $this->alterColumn('restaurant', 'province', $this->string()->notNull()); ~~~ **重新生成Model** ~~~ yii gii/model --tableName=restaurant --modelClass=Restaurant --ns=common\models ~~~ **實現后端驗證** ~~~ public function actionCreate() { $model = new Restaurant(); if (Yii::$app->request->isPost) { $name = $_POST['name']; $city = $_POST['city']; $province = $_POST['province']; $model->name = $name; $model->city = $city; $model->province = $province; if ($model->save()) { return $this->redirect('index'); } } return $this->render('create', ['model' => $model]); } /* @var $model common\models\Restaurant */ <pre><?= json_encode($model->errors) ?></pre> ~~~ ### 后端代碼(第二版) **修改前端提交參數名** ~~~ <input type="text" class="form-control" id="name" name="Restaurant[name]"> <input type="text" class="form-control" id="city" name="Restaurant[city]"> <input type="text" class="form-control" id="province" name="Restaurant[province]"> ~~~ **重寫后端代碼** ~~~ public function actionCreate() { $model = new Restaurant(); if ($model->load(Yii::$app->request->post())) { if ($model->save()) { return $this->redirect(['index']); } } return $this->render('create', ['model' => $model]); } ~~~ ### 探索 - load()函數何時返回true,何時返回false?返回true或false的時候,都做了什么工作? - save()函數何時返回true,何時返回false?返回true或false的時候,都做了什么工作? - 使用這樣的模型綁定函數,有什么好處?
                  <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>

                              哎呀哎呀视频在线观看