當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ActiveForm::validateMultiple方法代碼示例

本文整理匯總了PHP中yii\bootstrap\ActiveForm::validateMultiple方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActiveForm::validateMultiple方法的具體用法?PHP ActiveForm::validateMultiple怎麽用?PHP ActiveForm::validateMultiple使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\bootstrap\ActiveForm的用法示例。


在下文中一共展示了ActiveForm::validateMultiple方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 public function run()
 {
     Yii::setAlias('@unclead-examples', realpath(__DIR__ . '/../'));
     $models = $this->getItems();
     $request = Yii::$app->getRequest();
     if ($request->isPost && $request->post('ajax') !== null) {
         $data = Yii::$app->request->post('Item', []);
         foreach (array_keys($data) as $index) {
             $models[$index] = new Item();
         }
         Model::loadMultiple($models, Yii::$app->request->post());
         Yii::$app->response->format = Response::FORMAT_JSON;
         $result = ActiveForm::validateMultiple($models);
         return $result;
     }
     if (Model::loadMultiple($models, Yii::$app->request->post())) {
         // your magic
     }
     return $this->controller->render('@unclead-examples/views/tabular-input.php', ['models' => $models]);
 }
開發者ID:wqcsimple,項目名稱:wwhis-weixin,代碼行數:20,代碼來源:TabularInputAction.php

示例2: actionUpdate

 /**
  * Updates an existing Tour model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsCustomField = $model->customFields;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsCustomField, 'id', 'id');
         $modelsCustomField = Model::createMultiple(CustomField::classname(), $modelsCustomField);
         Model::loadMultiple($modelsCustomField, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsCustomField, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsCustomField), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsCustomField) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         CustomField::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsCustomField as $modelCustomField) {
                         $modelCustomField->tour_id = $model->id;
                         if (!($flag = $modelCustomField->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelsCustomField' => empty($modelsCustomField) ? [new CustomField()] : $modelsCustomField]);
 }
開發者ID:VitaliyProdan,項目名稱:tours_booking,代碼行數:49,代碼來源:TourController.php


注:本文中的yii\bootstrap\ActiveForm::validateMultiple方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。