当前位置: 首页>>代码示例>>PHP>>正文


PHP ActiveForm::validateMultiple方法代码示例

本文整理汇总了PHP中yii\widgets\ActiveForm::validateMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveForm::validateMultiple方法的具体用法?PHP ActiveForm::validateMultiple怎么用?PHP ActiveForm::validateMultiple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\widgets\ActiveForm的用法示例。


在下文中一共展示了ActiveForm::validateMultiple方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update

 public function update(AdminAction $adminAction)
 {
     /**
      * @var $model CmsTree
      */
     $model = $this->model;
     $relatedModel = $model->relatedPropertiesModel;
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel]);
     }
     if ($rr->isRequestPjaxPost()) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         if ($model->save() && $relatedModel->save()) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
             $model->refresh();
         } else {
             $errors = [];
             if ($model->getErrors()) {
                 foreach ($model->getErrors() as $error) {
                     $errors[] = implode(', ', $error);
                 }
             }
             \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save') . $errors);
         }
     }
     return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel]);
 }
开发者ID:skeeks-cms,项目名称:cms,代码行数:35,代码来源:AdminTreeController.php

示例2: performAjaxValidationMultiple

 protected function performAjaxValidationMultiple(array $models)
 {
     if (Yii::$app->request->isAjax && Model::loadMultiple($models, Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validateMultiple($models);
     }
 }
开发者ID:just-leo,项目名称:cardgame-serial,代码行数:7,代码来源:AjaxValidationTrait.php

示例3: actionUpdate

 public function actionUpdate($id)
 {
     $modelClassified = Classified::findOne($id);
     $modelImage = ClassifiedImage::find()->where(['classified_id' => $id])->all();
     //$modelImage = $modelClassified->id;
     if ($modelClassified->load(Yii::$app->request->post())) {
         $oldIDs = \yii\helpers\ArrayHelper::map($modelImage, 'id', 'classified_id');
         print_r($oldIDs);
         $modelImage = \common\models\Model::createMultiple(ClassifiedImage::classname(), $modelImage);
         \common\models\Model::loadMultiple($modelImage, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(\yii\helpers\ArrayHelper::map($modelImage, 'id', 'classified_id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return \yii\helpers\ArrayHelper::merge(\yii\widgets\ActiveForm::validateMultiple($modelImage), \yii\widgets\ActiveForm::validate($modelClassified));
         }
         // validate all models
         $valid = $modelClassified->validate();
         $valid = \common\models\Model::validateMultiple($modelImage) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $modelClassified->save(false)) {
                     if (!empty($deletedIDs)) {
                         ClassifiedImage::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelImage as $i => $modelImage) {
                         $modelImage->classified_id = $modelClassified->id;
                         if (empty($modelImage->imageFile)) {
                             $name = Yii::$app->security->generateRandomString();
                             $modelImage->imageFile = \yii\web\UploadedFile::getInstance($modelImage, "[{$i}]imageFile");
                             if ($modelImage->imageFile) {
                                 $modelImage->imageFile->saveAs('uploads/' . $name . '.' . $modelImage->imageFile->extension);
                                 //Upload files to server
                                 ////save path in db column
                                 $modelImage->image = 'uploads/' . $name . '.' . $modelImage->imageFile->extension;
                                 //$model->fileProfile->saveAs($model->image_profile);
                             }
                         }
                         if (!($flag = $modelImage->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->refresh();
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['modelClassified' => $modelClassified, 'modelImage' => empty($modelImage) ? [new ClassifiedImage()] : $modelImage]);
 }
开发者ID:deviardn,项目名称:diadoo,代码行数:56,代码来源:ReviewClassifiedController.php

示例4: performAjaxValidation

 /**
  * Performs ajax validation
  *
  * @param $model
  * @return \yii\console\Response|\yii\web\Response
  */
 protected function performAjaxValidation($model)
 {
     $result = $model instanceof Model ? ActiveForm::validate($model) : ActiveForm::validateMultiple($model);
     $response = Yii::$app->getResponse();
     if (!empty($result) && ($ajaxRedirect = Yii::$app->getSession()->get('site_ajax_redirect'))) {
         $response = $response->redirect($ajaxRedirect);
         Yii::$app->getSession()->remove('site_ajax_redirect');
     } else {
         $response->format = Response::FORMAT_JSON;
         $response->data = $result;
     }
     return $response;
 }
开发者ID:yii2-tools,项目名称:yii2-base,代码行数:19,代码来源:AjaxValidationTrait.php

示例5: update

 public function update(AdminAction $adminAction)
 {
     /**
      * @var $model CmsUser
      */
     $model = $this->model;
     $relatedModel = $model->relatedPropertiesModel;
     $passwordChange = new PasswordChangeForm(['user' => $model]);
     $passwordChange->scenario = PasswordChangeForm::SCENARION_NOT_REQUIRED;
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $passwordChange->load(\Yii::$app->request->post());
         return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel, $passwordChange]);
     }
     if ($rr->isRequestPjaxPost()) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $passwordChange->load(\Yii::$app->request->post());
         if ($model->save() && $relatedModel->save()) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved'));
             if ($passwordChange->new_password) {
                 if (!$passwordChange->changePassword()) {
                     \Yii::$app->getSession()->setFlash('error', "Пароль не изменен");
                 }
             }
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
             $model->refresh();
         } else {
             $errors = [];
             if ($model->getErrors()) {
                 foreach ($model->getErrors() as $error) {
                     $errors[] = implode(', ', $error);
                 }
             }
             \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save') . ". " . implode($errors));
         }
     }
     return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel, 'passwordChange' => $passwordChange]);
 }
开发者ID:skeeks-cms,项目名称:cms,代码行数:44,代码来源:AdminProfileController.php

示例6: actionStuinforeport

 public function actionStuinforeport()
 {
     $selected_list = $query = NULL;
     $student_data = array();
     $model = new StuMaster();
     $info = new StuInfo();
     $course = $batch = $section = null;
     if (!empty($_POST['s_info']) && !empty($_POST['StuMaster']['stu_master_course_id']) || (!empty($_POST['StuMaster']['report_batch_id']) || !empty($_POST['StuMaster']['report_section_id']) || !empty($_POST['StuMaster']['report_city']) || !empty($_POST['StuInfo']['stu_gender']))) {
         if (Yii::$app->request->isAjax) {
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validateMultiple([$model, $info]);
         }
         if (!empty($_POST['StuMaster']['stu_master_course_id'])) {
             $query .= "stu.stu_master_course_id=" . $_POST['StuMaster']['stu_master_course_id'] . " AND ";
         }
         if (!empty($_POST['StuMaster']['report_batch_id'])) {
             $query .= "stu.stu_master_batch_id=" . $_POST['StuMaster']['report_batch_id'] . " AND ";
         }
         if (!empty($_POST['StuMaster']['report_section_id'])) {
             $query .= "stu.stu_master_section_id=" . $_POST['StuMaster']['report_section_id'] . " AND ";
         }
         if (!empty($_POST['StuMaster']['report_city'])) {
             $query .= "add.stu_cadd_city=" . $_POST['StuMaster']['report_city'] . " AND ";
         }
         if (!empty($_POST['StuInfo']['stu_gender'])) {
             $query .= "s_info.stu_gender='" . $_POST['StuInfo']['stu_gender'] . "' AND ";
         }
         if (!empty($_POST['s_info'])) {
             $selected_list = $_POST['s_info'];
         }
         echo $model->validate();
         $query1 = new \yii\db\Query();
         $query1->select('*')->from('stu_master stu')->join('join', 'stu_info s_info', 's_info.stu_info_id = stu.stu_master_stu_info_id')->join('join', 'stu_address add', 'add.stu_address_id = stu.stu_master_stu_address_id')->where($query . 'stu.is_status = 0');
         $command = $query1->createCommand();
         $student_data = $command->queryAll();
         if (empty($student_data)) {
             \Yii::$app->getSession()->setFlash('studerror', "<i class='fa fa-exclamation-triangle'></i> <b> No Record For This Criteria.</b>");
             return $this->redirect(['stuinforeport']);
         }
         return $this->render('stu_info_report', ['student_data' => $student_data, 'selected_list' => $selected_list, 'query' => $query]);
         break;
     }
     return $this->render('stu_report_view', ['model' => $model, 'info' => $info, 'query' => $query, 'selected_list' => $selected_list]);
 }
开发者ID:aoopvn,项目名称:EduSec4.0.0,代码行数:44,代码来源:StudentController.php

示例7: actionIndex

 /**
  * Display all config paramters for $byModule.
  * @return mixed
  */
 public function actionIndex()
 {
     $models = Config::find()->where(['module' => $this->byModule])->orderBy(['id' => SORT_ASC])->indexBy('id')->all();
     if (Model::loadMultiple($models, Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validateMultiple($models, 'value');
         }
         $result = true;
         foreach ($models as $model) {
             $result = $result && $model->save(true, ['value']);
         }
         if ($result && Module::getInstance()->configManager->clearCache()) {
             Yii::$app->session->setFlash('success', Module::t('SAVE_SUCCESS'));
             return $this->redirect(['index']);
         }
     }
     return $this->render('index', ['models' => $models]);
 }
开发者ID:bupy7,项目名称:yii2-config,代码行数:23,代码来源:DefaultController.php

示例8: run

 /**
  * @return array|string|Response
  */
 public function run()
 {
     $models = ConfigModel::find()->orderBy(['sort' => SORT_ASC])->indexBy('name')->all();
     if (Model::loadMultiple($models, Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validateMultiple($models, 'value');
         }
         $result = true;
         /** @var ConfigModel $model */
         foreach ($models as $model) {
             $result = $result && $model->save(true, ['value']);
             Config::clearCache($model->name);
         }
         if ($result) {
             Yii::$app->session->setFlash('success', $this->successMessage);
             return $this->controller->redirect([$this->id]);
         }
     }
     return $this->controller->render($this->viewPath, ['models' => $models]);
 }
开发者ID:skinka,项目名称:yii2-config,代码行数:24,代码来源:ConfigAction.php

示例9: actionStuinforeport

 public function actionStuinforeport()
 {
     $student_data = $selected_list = [];
     $model = new StuMaster();
     $info = new StuInfo();
     if ($model->load(Yii::$app->request->post()) && $info->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validateMultiple([$model, $info]);
         }
         $selected_list = $_POST['s_info'];
         $query1 = new \yii\db\Query();
         $query1->select('*')->from('stu_master stu')->join('join', 'stu_info s_info', 's_info.stu_info_id = stu.stu_master_stu_info_id')->join('join', 'stu_address add', 'add.stu_address_id = stu.stu_master_stu_address_id')->where(['stu.is_status' => 0])->andFilterWhere(['stu.stu_master_course_id' => $model->stu_master_course_id])->andFilterWhere(['stu.stu_master_batch_id' => $model->report_batch_id])->andFilterWhere(['stu.stu_master_section_id' => $model->report_section_id])->andFilterWhere(['add.stu_cadd_city' => $model->report_city])->andFilterWhere(['s_info.stu_gender' => $info->stu_gender]);
         $command = $query1->createCommand();
         $student_data = $command->queryAll();
         Yii::$app->session->set('data["stuData"]', $student_data);
         Yii::$app->session->set('data["selection"]', $selected_list);
         if (empty($student_data)) {
             \Yii::$app->getSession()->setFlash('studerror', "<i class='fa fa-exclamation-triangle'></i> <b> " . Yii::t('report', 'No Record Found For This Criteria.') . "</b>");
             return $this->redirect(['stuinforeport']);
         }
         return $this->render('stu_info_report', ['student_data' => $student_data, 'selected_list' => $selected_list]);
     } else {
         if (Yii::$app->request->get('exportExcel')) {
             $file = $this->renderPartial('stu_info_report_excel', array('student_data' => Yii::$app->session->get('data["stuData"]'), 'selected_list' => Yii::$app->session->get('data["selection"]')));
             $fileName = "Employee_info_report" . date('YmdHis') . '.xls';
             $options = ['mimeType' => 'application/vnd.ms-excel'];
             return Yii::$app->excel->exportExcel($file, $fileName, $options);
         } else {
             if (Yii::$app->request->get('exportPDF')) {
                 $html = $this->renderPartial('stu_info_report_pdf', array('student_data' => Yii::$app->session->get('data["stuData"]'), 'selected_list' => Yii::$app->session->get('data["selection"]')));
                 ob_clean();
                 return Yii::$app->pdf->exportData('Employee Info Report', 'Employee_info_report', $html);
             }
         }
     }
     return $this->render('stu_report_view', ['model' => $model, 'info' => $info, 'selected_list' => $selected_list]);
 }
开发者ID:EduSec,项目名称:EduSec,代码行数:38,代码来源:StudentController.php

示例10: actionUpdate

 /**
  * Updates an existing Po 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);
     //
     //        if ($model->load(Yii::$app->request->post()) && $model->save()) {
     //            return $this->redirect(['view', 'id' => $model->id]);
     //        } else {
     //            return $this->render('update', [
     //                'model' => $model,
     //            ]);
     //        }
     $model = $this->findModel($id);
     $modelsPoItems = $model->poItems;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsPoItems, 'id', 'id');
         $modelsPoItems = Model::createMultiple(Poitem::classname(), $modelsPoItems);
         Model::loadMultiple($modelsPoItems, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItems, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsPoItems), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsPoItems) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         Poitem::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsPoItems as $modelPoItem) {
                         $modelPoItem->po_id = $model->id;
                         if (!($flag = $modelPoItem->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, 'modelsPoItems' => empty($modelsPoItems) ? [new Poitem()] : $modelsPoItems]);
 }
开发者ID:sydorenkovd,项目名称:yiiadv,代码行数:58,代码来源:PoController.php

示例11: actionSignup

 public function actionSignup()
 {
     $model = new SignupForm();
     $model_pets = [];
     for ($i = 1; $i < Yii::$app->params['countPetsInSignup']; $i++) {
         $model_pets["pet_{$i}"] = new PetForm();
     }
     if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($model_pets, Yii::$app->request->post())) {
         $model_pet_valid = [];
         for ($i = 1; $i <= $model->count_pets; $i++) {
             $model_pet_valid["pet_{$i}"] = clone $model_pets["pet_{$i}"];
         }
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             $erros = ActiveForm::validate($model);
             $erros_pets = ActiveForm::validateMultiple($model_pet_valid);
             return array_merge($erros, $erros_pets);
         }
         if (Model::validateMultiple($model_pet_valid) && $model->signup()) {
             foreach ($model_pet_valid as $pet) {
                 try {
                     /**@var $pet PetForm */
                     if (!PurinaAuth::init()->createUserPet($pet->name, $pet->gender, $pet->year, $pet->month, $pet->breed)) {
                         $data = PurinaAuth::getData();
                         if ($data->message) {
                             Yii::$app->session->setFlash("error", $data->message);
                         }
                     }
                 } catch (\Exception $e) {
                     break;
                 }
             }
             return $this->goHome();
         } else {
             $validation = true;
             for ($i = 1; $i <= $model->count_pets; $i++) {
                 /**
                  * @var $model_valid PetForm
                  */
                 $model_valid = $model_pet_valid["pet_{$i}"];
                 if ($model_valid->hasErrors()) {
                     $validation = false;
                     $model_pets["pet_{$i}"] = clone $model_valid;
                 }
             }
             if (!$validation) {
                 $model->validate();
             }
         }
     }
     return $this->render('signup', ['model' => $model, 'model_pets' => $model_pets]);
 }
开发者ID:an2riy,项目名称:purina,代码行数:52,代码来源:SiteController.php

示例12: Subject

$users = User::find()->all();
$scholars = Scholar::find()->all();
$model = new Subject();
$modelCustomer = new Grade();
$modelsAddress = [new Grade()];
foreach ($users as $user) {
    foreach ($scholars as $scholar) {
        if ($user->username == $username && $user->id == $scholar->scholar_user_id) {
            $modelCustomer->subject_scholar_scholar_id = $scholar->scholar_id;
            if ($modelCustomer->load(Yii::$app->request->post())) {
                $modelsAddress = GroupGrade::createMultiple(Grade::classname());
                GroupGrade::loadMultiple($modelsAddress, Yii::$app->request->post());
                // ajax validation
                if (Yii::$app->request->isAjax) {
                    Yii::$app->response->format = Response::FORMAT_JSON;
                    return ArrayHelper::merge(ActiveForm::validateMultiple($modelsAddress), ActiveForm::validate($modelCustomer));
                }
                // validate all models
                $valid = $modelCustomer->validate();
                $valid = GroupGrade::validateMultiple($modelsAddress) && $valid;
                if ($valid) {
                    $transaction = \Yii::$app->db->beginTransaction();
                    try {
                        // if($flag = $modelCustomer->save(false)){
                        foreach ($modelsAddress as $modelAddress) {
                            $modelAddress->subject_scholar_scholar_id = $modelCustomer->subject_scholar_scholar_id;
                            $modelAddress->grade_school_year_start = $modelCustomer->grade_school_year_start;
                            $modelAddress->grade_school_year_end = $modelCustomer->grade_school_year_end;
                            $selectSchool = ArrayHelper::map(Scholar::find()->where(['scholar_id' => $modelAddress->subject_scholar_scholar_id])->all(), 'school_school_id', 'school_school_id');
                            $schoolID = array_values($selectSchool)[0];
                            $modelAddress->subject_scholar_school_school_id = $schoolID;
开发者ID:seans888,项目名称:SMF-Project,代码行数:31,代码来源:groupcreate.php

示例13: validateModel

 /**
  * Performs validation on the provided model and $_POST data
  *
  * @param \infoweb\pages\models\Page $model The page model
  * @param array $post The $_POST data
  * @return array
  */
 protected function validateModel($model, $post)
 {
     $languages = Yii::$app->params['languages'];
     // Populate the model with the POST data
     $model->load($post);
     // Parent is root
     if (empty($post[StringHelper::basename(MenuItem::className())]['parent_id'])) {
         $model->parent_id = 0;
         $model->level = 0;
     } else {
         $parent = MenuItem::findOne($post[StringHelper::basename(MenuItem::className())]['parent_id']);
         $model->parent_id = $parent->id;
         $model->level = $parent->level + 1;
     }
     // Create an array of translation models and populate them
     $translationModels = [];
     // Insert
     if ($model->isNewRecord) {
         foreach ($languages as $languageId => $languageName) {
             $translationModels[$languageId] = new MenuItemLang(['language' => $languageId]);
         }
         // Update
     } else {
         $translationModels = ArrayHelper::index($model->getTranslations()->all(), 'language');
     }
     Model::loadMultiple($translationModels, $post);
     // Validate the model and translation
     $response = array_merge(ActiveForm::validate($model), ActiveForm::validateMultiple($translationModels));
     // Return validation in JSON format
     Yii::$app->response->format = Response::FORMAT_JSON;
     return $response;
 }
开发者ID:infoweb-internet-solutions,项目名称:yii2-cms-menu,代码行数:39,代码来源:MenuItemController.php

示例14: update

 public function update(AdminAction $adminAction)
 {
     /**
      * @var $model CmsContentElement
      */
     $model = $this->model;
     $relatedModel = $model->relatedPropertiesModel;
     $shopProduct = ShopProduct::find()->where(['id' => $model->id])->one();
     $productPrices = [];
     if (!$shopProduct) {
         $shopProduct = new ShopProduct(['id' => $model->id]);
         $shopProduct->save();
     } else {
         if ($typePrices = ShopTypePrice::find()->where(['!=', 'def', Cms::BOOL_Y])->all()) {
             foreach ($typePrices as $typePrice) {
                 $productPrice = ShopProductPrice::find()->where(['product_id' => $shopProduct->id, 'type_price_id' => $typePrice->id])->one();
                 if (!$productPrice) {
                     $productPrice = new ShopProductPrice(['product_id' => $shopProduct->id, 'type_price_id' => $typePrice->id]);
                 }
                 if ($post = \Yii::$app->request->post()) {
                     $data = ArrayHelper::getValue($post, 'prices.' . $typePrice->id);
                     $productPrice->load($data, "");
                 }
                 $productPrices[] = $productPrice;
             }
         }
     }
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $shopProduct->load(\Yii::$app->request->post());
         return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel, $shopProduct]);
     }
     if ($rr->isRequestPjaxPost()) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $shopProduct->load(\Yii::$app->request->post());
         /**
          * @var $productPrice ShopProductPrice
          */
         foreach ($productPrices as $productPrice) {
             if ($productPrice->save()) {
             } else {
                 \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/shop/app', 'Check the correctness of the prices'));
             }
         }
         if ($model->save() && $relatedModel->save() && $shopProduct->save()) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/shop/app', 'Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
             $model->refresh();
         } else {
             $errors = [];
             if ($model->getErrors()) {
                 foreach ($model->getErrors() as $error) {
                     $errors[] = implode(', ', $error);
                 }
             }
             \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/shop/app', 'Could not save') . $errors);
         }
     }
     if (!$shopProduct->baseProductPrice) {
         $baseProductPrice = new ShopProductPrice(['type_price_id' => \Yii::$app->shop->baseTypePrice->id, 'currency_code' => \Yii::$app->money->currencyCode, 'product_id' => $model->id]);
         $baseProductPrice->save();
     }
     return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel, 'shopProduct' => $shopProduct, 'productPrices' => $productPrices, 'baseProductPrice' => $shopProduct->getBaseProductPrice()->one()]);
 }
开发者ID:skeeks-cms,项目名称:cms-shop,代码行数:70,代码来源:AdminCmsContentElementController.php

示例15: actionProfile

 /**
  * Allows users to view or update their profile.
  * @param  boolean $update
  * @return string
  */
 public function actionProfile($update = false)
 {
     /** @var ProfileForm */
     $model = $this->module->createFormModel('ProfileForm');
     $model->setAttributes($model->getIdentity()->getIdentityAttributes());
     $loadedModel = $model->load($_POST);
     /** @var PasswordForm */
     $passwordForm = $this->module->createFormModel('PasswordForm');
     $loadedPassword = isset($_POST[$passwordForm->formName()]) && trim($_POST[$passwordForm->formName()]['newPassword']) !== '' && $passwordForm->load($_POST);
     if ($loadedModel) {
         if ($model->getIdentity() instanceof PictureIdentityInterface && !empty($model->pictureUploadRules)) {
             $model->picture = \yii\web\UploadedFile::getInstance($model, 'picture');
         }
         $passwordForm->password = $model->password;
     }
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $models = [];
         if ($loadedModel) {
             $models[] = $model;
         }
         if ($loadedPassword) {
             $models[] = $passwordForm;
         }
         return \yii\widgets\ActiveForm::validateMultiple($models);
     }
     $flashes = ['success' => [], 'error' => []];
     /**
      * Only try to set new password if it has been specified in the form.
      * The current password could have been used to authorize other changes.
      */
     if ($loadedPassword) {
         if ($passwordForm->validate() && $passwordForm->resetPassword($model->getIdentity())) {
             $flashes['success'][] = Yii::t('usr', 'Changes have been saved successfully.');
         } else {
             $flashes['error'][] = Yii::t('usr', 'Failed to change password.');
         }
     }
     if ($loadedModel && empty($flashes['error'])) {
         if ($model->validate()) {
             $oldEmail = $model->getIdentity()->getEmail();
             if ($model->save($this->module->requireVerifiedEmail)) {
                 if ($this->module->requireVerifiedEmail && $oldEmail != $model->email) {
                     if ($this->sendEmail($model, 'verify')) {
                         $flashes['success'][] = Yii::t('usr', 'An email containing further instructions has been sent to provided email address.');
                     } else {
                         $flashes['error'][] = Yii::t('usr', 'Failed to send an email.') . ' ' . Yii::t('usr', 'Try again or contact the site administrator.');
                     }
                 }
                 $flashes['success'][] = Yii::t('usr', 'Changes have been saved successfully.');
                 if (!empty($flashes['success'])) {
                     Yii::$app->session->setFlash('success', implode('<br/>', $flashes['success']));
                 }
                 if (!empty($flashes['error'])) {
                     Yii::$app->session->setFlash('error', implode('<br/>', $flashes['error']));
                 }
                 return $this->redirect(['profile']);
             } else {
                 $flashes['error'][] = Yii::t('usr', 'Failed to update profile.') . ' ' . Yii::t('usr', 'Try again or contact the site administrator.');
             }
         }
     }
     if (!empty($flashes['success'])) {
         Yii::$app->session->setFlash('success', implode('<br/>', $flashes['success']));
     }
     if (!empty($flashes['error'])) {
         Yii::$app->session->setFlash('error', implode('<br/>', $flashes['error']));
     }
     if ($update) {
         return $this->render('updateProfile', ['model' => $model, 'passwordForm' => $passwordForm]);
     } else {
         return $this->render('viewProfile', ['model' => $model]);
     }
 }
开发者ID:rumatakira,项目名称:yii2-usr,代码行数:79,代码来源:DefaultController.php


注:本文中的yii\widgets\ActiveForm::validateMultiple方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。