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


PHP Model::validateMultiple方法代码示例

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


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

示例1: actionCreate

 /**
  * Anlegen eines Benutzers
  * 
  * @return \yii\web\View
  * @author KAS <kassel@weitkamper.de> 28.07.2015
  */
 public function actionCreate()
 {
     Yii::$app->view->params['headline'] = 'Benutzer anlegen';
     $model = new User();
     //----------------------------------------------------------------------
     $post = \Yii::$app->request->post();
     if ($model->load($post)) {
         $authArr = [];
         foreach ($post['Auth'] as $authData) {
             $authArr[] = new Auth($authData);
         }
         // Daten Validieren und Zuordnen -----------------------------------
         if (Model::loadMultiple($authArr, $post) && Model::validateMultiple($authArr)) {
             // aus den Auth Objekten machen wir arrays,
             // damit wir das in die Mongo speichern können
             $model->auth = array_map(function ($a) {
                 return $a->toArray();
             }, $authArr);
             // Speichern ---------------------------------------------------
             $model->save();
             // Benutzer benachrichtigen ------------------------------------
             \Yii::$app->session->setFlash('success', 'Benutzer wurde erfolgreich angelegt!', TRUE);
             // Neue Daten laden, da wir in den Models Veränderungen vornehmen
             $model->refresh();
         }
     }
     // Defaultwerte festlegen ----------------------------------------------
     $model->created_at = new \MongoDate();
     $model->updated_at = new \MongoDate();
     $model->role = "Normal";
     //----------------------------------------------------------------------
     return $this->render('create', ['model' => $model]);
 }
开发者ID:KasselR,项目名称:yii2-kr,代码行数:39,代码来源:UsersController.php

示例2: update

 public function update()
 {
     /**
      * @var $model SourceMessage
      */
     $model = $this->model;
     $model->initMessages();
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         Model::loadMultiple($model->messages, \Yii::$app->getRequest()->post());
         return Model::validateMultiple($model->messages);
         //return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestPjaxPost()) {
         if (Model::loadMultiple($model->messages, \Yii::$app->getRequest()->post()) && Model::validateMultiple($model->messages)) {
             $model->saveMessages();
             //\Yii::$app->getSession()->setFlash('success', \Yii::t('app','Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
         } else {
             //\Yii::$app->getSession()->setFlash('error', \Yii::t('app','Could not save'));
         }
     }
     return $this->render('_form', ['model' => $model]);
 }
开发者ID:smallmirror62,项目名称:cms,代码行数:27,代码来源:AdminMessageController.php

示例3: actionUser

 public function actionUser()
 {
     $model = new ModelInstallation();
     $model_user = new User();
     $model_user->setScenario('reset');
     $model->setScenario('username_installation');
     if ($model->load(Yii::$app->request->post()) && $model_user->load(Yii::$app->request->post()) && Model::validateMultiple([$model, $model_user])) {
         $model->titleInstallation();
         $role = Yii::$app->getModule("user")->model("Role");
         $model_user->role_id = $role::ROLE_ADMIN;
         $model_user->status = User::STATUS_ACTIVE;
         $model_user->create_time = date('Y-m-d H:i:s');
         $model_user->create_ip = Yii::$app->request->getUserHost();
         $model_user->api_key = Yii::$app->security->generateRandomString();
         $model_user->auth_key = Yii::$app->security->generateRandomString();
         $model_user->save();
         $profile_data = Yii::$app->getModule("user")->model("Profile");
         $profile_data->user_id = $model_user->id;
         $profile_data->full_name = $model_user->username;
         $profile_data->create_time = date('Y-m-d H:i:s');
         $profile_data->save(FALSE);
         return $this->refresh();
     }
     return $this->render('username_installation', ['model' => $model, 'model_user' => $model_user, 'form_title' => 'System configuration', 'page_info' => '']);
 }
开发者ID:AtuinCMS,项目名称:installation,代码行数:25,代码来源:SiteController.php

示例4: saveTemplate

 /**
  * Populates template and related models with the data, validates and saves
  * @param Template $template
  * @param array $data
  * @return bool
  */
 public function saveTemplate(Template $template, $data)
 {
     if ($template->load($data)) {
         $widgetAreas = $this->loadWidgetAreas($data);
         $widgets = $this->loadWidgets($data, 'Widgets');
         $valid = true;
         $valid = $template->validate() && $valid;
         $first = reset($widgetAreas);
         $valid = Model::validateMultiple($widgetAreas, array_diff($first->activeAttributes(), ['template_id'])) && $valid;
         $valid = Model::validateMultiple($widgets) && $valid;
         if ($valid && $template->save(false)) {
             if ($widgetAreas) {
                 foreach ($widgetAreas as $area) {
                     $area->template_id = $template->id;
                     if ($widgets) {
                         $this->setWidgets($area, $widgets);
                     }
                     $area->save();
                 }
             }
             return true;
         } else {
             if ($widgetAreas) {
                 $template->populateRelation('widgetAreas', $widgetAreas);
             }
             if ($widgets) {
                 $this->linkWidgets($widgetAreas, $widgets);
             }
         }
     }
     return false;
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:38,代码来源:TemplateManager.php

示例5: actionIndex

 /**
  * Lists all models.
  * @return mixed
  */
 public function actionIndex()
 {
     $sourceLanguage = 'en-US';
     $languages = Yii::$app->yee->languages;
     $categories = MessageSource::getMessageCategories();
     unset($languages[$sourceLanguage]);
     $currentLanguage = Yii::$app->getRequest()->get('translation', NULL);
     $currentCategory = Yii::$app->getRequest()->get('category', NULL);
     if (!in_array($currentLanguage, array_keys($languages))) {
         $currentLanguage = NULL;
     }
     if (!in_array($currentCategory, array_keys($categories))) {
         $currentCategory = NULL;
     }
     if ($currentLanguage && $currentCategory) {
         Message::initMessages($currentCategory, $currentLanguage);
         $messageIds = MessageSource::getMessageIdsByCategory($currentCategory);
         $sourceTable = MessageSource::tableName();
         $messageTable = Message::tableName();
         $messages = Message::find()->andWhere(['IN', 'source_id', $messageIds])->andWhere(['language' => $currentLanguage])->indexBy('id')->all();
     } else {
         $messages = [];
     }
     if (User::hasPermission('updateTranslations') && Message::loadMultiple($messages, Yii::$app->request->post()) && Model::validateMultiple($messages)) {
         foreach ($messages as $message) {
             $message->save(false);
         }
         Yii::$app->session->setFlash('crudMessage', 'Your item has been updated.');
         return $this->refresh();
     }
     return $this->render('index', ['messages' => $messages, 'languages' => $languages, 'categories' => $categories, 'currentLanguage' => $currentLanguage, 'currentCategory' => $currentCategory]);
 }
开发者ID:yeesoft,项目名称:yii2-yee-translation,代码行数:36,代码来源:DefaultController.php

示例6: actionUpdate

 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  *
  * @param  integer $id The user id.
  * @return string|\yii\web\Response
  *
  * @throws NotFoundHttpException
  */
 public function actionUpdate($id)
 {
     // get role
     $role = Role::findOne(['user_id' => $id]);
     // get user details
     $user = $this->findModel($id);
     // only The Creator can update everyone`s roles
     // admin will not be able to update role of theCreator
     if (!Yii::$app->user->can('theCreator')) {
         if ($role->item_name === 'theCreator') {
             return $this->goHome();
         }
     }
     // load user data with role and validate them
     if ($user->load(Yii::$app->request->post()) && $role->load(Yii::$app->request->post()) && Model::validateMultiple([$user, $role])) {
         // only if user entered new password we want to hash and save it
         if ($user->password) {
             $user->setPassword($user->password);
         }
         // if admin is activating user manually we want to remove account activation token
         if ($user->status == User::STATUS_ACTIVE && $user->account_activation_token != null) {
             $user->removeAccountActivationToken();
         }
         $user->save(false);
         $role->save(false);
         return $this->redirect(['view', 'id' => $user->id]);
     } else {
         return $this->render('update', ['user' => $user, 'role' => $role]);
     }
 }
开发者ID:komsin,项目名称:yiiexpert1,代码行数:39,代码来源:UserController.php

示例7: actionWrong

 public function actionWrong()
 {
     if (Yii::$app->getRequest()->getMethod() === 'OPTIONS') {
         return true;
     }
     $errors = [];
     $answers = Yii::$app->request->post('AnswersWrong');
     foreach ($answers['answers'] as $ans_id => $answer) {
         $modelArray[] = new AnswerWrong();
         $assign['AnswerWrong'][] = ['word_id' => $answer['id'], 'user_id' => Yii::$app->user->id, 'answer' => $answer['answer'], 'type' => $answer['type']];
     }
     if (Model::loadMultiple($modelArray, $assign) && Model::validateMultiple($modelArray)) {
         $errors = false;
         foreach ($modelArray as $model_answer) {
             if (!$model_answer->save()) {
                 $errors[] = Html::errorSummary($model_answer);
             }
         }
         if ($errors) {
             return $errors;
         }
     } else {
         return 'No record answers';
     }
 }
开发者ID:aekkapun,项目名称:YiiAngulario,代码行数:25,代码来源:AnswerController.php

示例8: actionSave

 public function actionSave($id)
 {
     // ---------------------- CHECK IS AJAX REQUEST ------------------------
     if (!Yii::$app->getRequest()->isAjax) {
         return $this->redirect(['/translations']);
     }
     // ------------------ SET JSON FORMAT FOR RESPONSE ---------------------
     // @see https://github.com/samdark/yii2-cookbook/blob/master/book/response-formats.md
     Yii::$app->getResponse()->format = \yii\web\Response::FORMAT_JSON;
     // --------------------- SET DEFAULT RESPONSE --------------------------
     $response = array('status' => 'error', 'message' => Module::t('An unexpected error occured!'));
     // --------------------- SAVE TRANSLATION BY ID ------------------------
     // @see vendor\zelenin\yii2-i18n-module\controllers\DefaultController::actionUpdate
     $model = $this->findModel($id);
     $model->initMessages();
     if (Model::loadMultiple($model->messages, Yii::$app->getRequest()->post()) && Model::validateMultiple($model->messages)) {
         $model->saveMessages();
         // clear translation cache
         if ($categories = AppHelper::getRequestParam('categories')) {
             foreach ($categories as $language => $category) {
                 Yii::$app->cache->delete(['yii\\i18n\\DbMessageSource', $category, $language]);
             }
         }
         $response['status'] = 'success';
         $response['message'] = 'Translation successfuly saved.';
         $response['params'] = AppHelper::getRequestParams();
     }
     return $response;
 }
开发者ID:uran1980,项目名称:yii2-translate-panel,代码行数:29,代码来源:DefaultController.php

示例9: runTabular

 /**
  * @inheritDoc
  */
 protected function runTabular($models)
 {
     if ($success = Model::validateMultiple($models)) {
         foreach ($models as $model) {
             $model->save(false);
         }
     }
     return ['success' => $success, 'modeldata' => ArrayHelper::toArray($models)];
 }
开发者ID:jwaldock,项目名称:yii2-ajaxform,代码行数:12,代码来源:AjaxSubmitAction.php

示例10: actionConfig

 public function actionConfig()
 {
     $configs = Config::find()->indexBy('id')->all();
     if (Model::loadMultiple($configs, \Yii::$app->request->post()) && Model::validateMultiple($configs)) {
         foreach ($configs as $config) {
             $config->save(false);
         }
         return $this->redirect('config');
     }
     return $this->render('config', ['configs' => $configs]);
 }
开发者ID:zhangsong,项目名称:yii,代码行数:11,代码来源:SystemController.php

示例11: actionUpdate

 public function actionUpdate($id)
 {
     $flatPage = $this->findFlatPage($id);
     $translations = $flatPage->initializeTranslations();
     if ($flatPage->load(Yii::$app->request->post()) && Model::loadMultiple($translations, Yii::$app->request->post()) && Model::validateMultiple($translations) && $flatPage->save()) {
         $flatPage->saveTranslations($translations);
         Yii::$app->session->setFlash('success', Yii::t('app', "Page {$flatPage} updated successfully"));
         return $this->redirect(['index']);
     }
     return $this->render('update', compact('flatPage', 'translations'));
 }
开发者ID:HeavyDots,项目名称:heavyCMS,代码行数:11,代码来源:FlatPageController.php

示例12: actionUpdate

 public function actionUpdate($id)
 {
     $blogCategory = $this->findBlogCategory($id);
     $translations = $blogCategory->initializeTranslations();
     if ($blogCategory->load($_POST) && Model::loadMultiple($translations, $_POST) && Model::validateMultiple($translations) && $blogCategory->save()) {
         $blogCategory->saveTranslations($translations);
         Yii::$app->session->setFlash('success', Yii::t('app', "Blog Category {$blogCategory->name} updated successfully"));
         return $this->redirect(['index']);
     }
     return $this->render('update', compact('blogCategory', 'translations'));
 }
开发者ID:eltortuganegra,项目名称:heavyCMS,代码行数:11,代码来源:BlogCategoryController.php

示例13: actionIndex

 public function actionIndex()
 {
     $settings = Setting::find()->indexBy('key')->all();
     if (Model::loadMultiple($settings, Yii::$app->request->post()) && Model::validateMultiple($settings)) {
         foreach ($settings as $setting) {
             $setting->save(false);
         }
         Yii::$app->session->addFlash('success', 'تنظیمات با موفقیت ذخیره شد.');
         return $this->redirect('index');
     }
     return $this->render('index', ['settings' => $settings]);
 }
开发者ID:ahb360,项目名称:cms,代码行数:12,代码来源:ManageController.php

示例14: actionIndex

 /**
  * Performs batch updated of application configuration records.
  */
 public function actionIndex()
 {
     /* @var $configManager \yii2tech\config\Manager */
     $configManager = Yii::$app->get('configManager');
     $models = $configManager->getItems();
     if (Model::loadMultiple($models, Yii::$app->request->post()) && Model::validateMultiple($models)) {
         $configManager->saveValues();
         Yii::$app->session->setFlash('success', Yii::t('admin', 'Configuration updated.'));
         return $this->refresh();
     }
     return $this->render('index', ['models' => $models]);
 }
开发者ID:yii2tech,项目名称:project-template,代码行数:15,代码来源:ConfigController.php

示例15: actionIndex

 /**
  * Отображение и сохранение конфигурации
  * @return string|\yii\web\Response
  */
 public function actionIndex()
 {
     $searchModel = new Config(["scenario" => ActiveRecord::SCENARIO_SEARCH]);
     $models = Config::find()->orderBy(["id" => SORT_DESC])->all();
     if (Model::loadMultiple($models, Yii::$app->request->post()) && Model::validateMultiple($models)) {
         foreach ($models as $setting) {
             $setting->save(false);
         }
         return $this->refresh();
     }
     return $this->render('index', ['models' => $models, "searchModel" => $searchModel]);
 }
开发者ID:frostiks25,项目名称:rzwebsys7,代码行数:16,代码来源:ConfigController.php


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