当前位置: 首页>>代码示例>>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;未经允许,请勿转载。