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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                >場景的使用結合驗證來操作,場景的意思就是說,在操作某個表對象的時候,會有新增,查詢,修改,刪除等。這些操作就各自對應一個場景,這樣就可以方便的為每個場景進行驗證邏輯的代碼編寫。 [TOC] #### 1. 創建frontend\models\User.php ,定義其scenarios以及rules ~~~ public function scenarios() { //繼承了父類的default場景,并新增了一個update場景(只驗證和操作一個字段《real_name》) return array_merge(parent::scenarios(),[ 'update' => ['real_name'], ]); } /** * @inheritdoc */ public function rules() { return [ [['real_name','age','job_name'], 'required'], [['age'], 'integer'], [['real_name','job_name'], 'string', 'max' => 50], [['created_at'], 'safe'], ]; } ~~~ #### 2. 在controller中調用時,使用 ~~~ //新增時,因為沒有設置Scenario,所以引用的是default場景,則是默認所有的rules規則都執行。 public function actionCreate() { $model = new User(); if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { $this->layout = 'iframe'; return $this->render('create', [ 'model' => $model, ]); } } //修改時候,只對real_name字段進行修改和驗證 public function actionUpdate($id) { $model = $this->findModel($id); $model->setScenario('update'); if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('update', [ 'model' => $model, ]); } } ~~~ > 參考網址 1. http://www.manks.top/how-to-set-scenario-in-yii2.html
                  <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>

                              哎呀哎呀视频在线观看