示例#1
显示文件
文件: UsersController.php 项目: KasselR/yii2-kr
/** * 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]); }
示例#2
显示文件
文件: AdminMessageController.php 项目: smallmirror62/cms
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]); }
示例#3
显示文件
文件: AjaxValidationTrait.php 项目: just-leo/cardgame-serial
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); } }
示例#4
显示文件
文件: AnswerController.php 项目: aekkapun/YiiAngulario
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'; } }
示例#5
显示文件
文件: DefaultController.php 项目: uran1980/yii2-translate-panel
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; }
示例#6
显示文件
文件: MetaTagBehavior.php 项目: hanterrian/yii2-meta-tag-module
/** * Delete old meta tags and save new meta tags */ public function saveMetaTags() { $existing = $this->getExistingMetaTags(); Model::loadMultiple($existing, $this->metaTags, ''); foreach ($existing as $tags) { $tags->save(false); } }
示例#7
显示文件
文件: TemplateManager.php 项目: manyoubaby123/imshop
/** * Loads widget areas from data array. * * @param array $data * @param string $formName * @return WidgetArea[] */ public function loadWidgetAreas($data, $formName = null) { $widgetAreas = $this->getWidgetAreas($data, $formName); $loaded = []; if (Model::loadMultiple($widgetAreas, $data, $formName)) { $loaded = $widgetAreas; } return $loaded; }
示例#8
显示文件
文件: DefaultController.php 项目: mark38/yii2-site-mng
public function actionRequests($tasks_id = null, $id = null, $new = null) { if ($tasks_id) { $task = Tasks::findOne($tasks_id); } elseif (!Tasks::find()->where(['state' => 1])->one()) { $task = new Tasks(); $task->save(); } else { $task = Tasks::find()->where(['state' => 1])->one(); } $certificates = Certificates::find()->where(['state' => 1])->all(); if ($new) { $request = new Requests(); $requested_certificates = []; foreach ($certificates as $certificate) { $requested_certificates[$certificate->id] = new RequestedCertificates(); $requested_certificates[$certificate->id]->certificates_id = $certificate->id; } } else { $request = Requests::findOne($id); $requested_certificates = []; foreach ($certificates as $certificate) { if ($request && RequestedCertificates::find()->where(['requests_id' => $request->id, 'certificates_id' => $certificate->id])->one()) { $requested_certificates[$certificate->id] = RequestedCertificates::find()->where(['requests_id' => $request->id, 'certificates_id' => $certificate->id])->one(); } else { $requested_certificates[$certificate->id] = new RequestedCertificates(); $requested_certificates[$certificate->id]->certificates_id = $certificate->id; } } } $companies = ArrayHelper::map(Companies::find()->all(), 'id', 'name'); $requests = new ActiveDataProvider(['query' => Requests::find()->where(['tasks_id' => $tasks_id]), 'pagination' => ['pageSize' => 20]]); if ($request && $request->load(Yii::$app->request->post())) { $request->tasks_id = $task->id; $request->save(); if (Model::loadMultiple($requested_certificates, Yii::$app->request->post())) { foreach ($requested_certificates as $key => $requested_certificate) { if (!$requested_certificate->wagons) { $requested_certificate->delete(); continue; } $requested_certificate->requests_id = $request->id; $requested_certificate->save(); } } if ($new) { Yii::$app->getSession()->setFlash('success', 'Запрос добавлен'); } else { Yii::$app->getSession()->setFlash('success', 'Изменения сохранены'); } } else { return $this->render('requests', ['task' => $task, 'companies' => $companies, 'requests' => $requests, 'request' => $request, 'requested_certificates' => $requested_certificates, 'new' => $new, 'excels' => FilePaths::find()->where(['tasks_id' => $tasks_id, 'type' => 'excel'])->all() ? FilePaths::find()->where(['tasks_id' => $tasks_id, 'type' => 'excel'])->all() : '', 'excel_zip' => FilePaths::find()->where(['tasks_id' => $tasks_id, 'type' => 'excel-zip'])->one() ? FilePaths::find()->where(['tasks_id' => $tasks_id, 'type' => 'excel-zip'])->one()->path : '', 'companies_zip' => FilePaths::find()->where(['tasks_id' => $tasks_id, 'type' => 'companies-zip'])->all() ? FilePaths::find()->where(['tasks_id' => $tasks_id, 'type' => 'companies-zip'])->all() : '', 'lost' => CertificatesLost::find()->where(['tasks_id' => $tasks_id])->all() ? CertificatesLost::find()->where(['tasks_id' => $tasks_id])->all() : '']); } return $this->redirect(['/certificates/requests', 'tasks_id' => $task->id]); }
示例#9
显示文件
文件: FlatPageController.php 项目: HeavyDots/heavyCMS
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')); }
示例#10
显示文件
文件: TourController.php 项目: vfrbgt/test-task-yii2
/** * Creates a new Tour model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Tour(); $modelsOptionValue = [new CustomTourFields()]; Model::loadMultiple($modelsOptionValue, Yii::$app->request->post()); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'modelsOptionValue' => empty($modelsOptionValue) ? [new CustomTourFields()] : $modelsOptionValue]); } }
示例#11
显示文件
文件: BlogCategoryController.php 项目: eltortuganegra/heavyCMS
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')); }
示例#12
显示文件
文件: SystemController.php 项目: zhangsong/yii
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]); }
示例#13
显示文件
文件: ManageController.php 项目: ahb360/cms
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]); }
示例#14
显示文件
文件: VariationTrait.php 项目: Ryadnov/admin
/** * Populates the main model and variation models with input data. * @param Model $model main model instance. * @param array $data the data array to load, typically `$_POST` or `$_GET`. * @return boolean whether expected forms are found in `$data`. */ protected function load($model, $data) { if (!$model->load($data)) { return false; } foreach ($this->getVariationModelBatches($model) as $variationName => $variationModels) { if (!Model::loadMultiple($variationModels, $data)) { return false; } } return true; }
示例#15
显示文件
文件: ConfigController.php 项目: yii2tech/project-template
/** * 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]); }
示例#16
显示文件
文件: ConfigController.php 项目: frostiks25/rzwebsys7
/** * Отображение и сохранение конфигурации * @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]); }
示例#17
显示文件
文件: DefaultController.php 项目: zolotarev/yii2-i18n-module
/** * @param integer $id * @return string|Response */ public function actionUpdate($id) { /** @var SourceMessage $model */ $model = $this->findModel($id); $model->initMessages(); if (Model::loadMultiple($model->messages, Yii::$app->getRequest()->post()) && Model::validateMultiple($model->messages)) { $model->saveMessages(); Yii::$app->getSession()->setFlash('alert', ['body' => Module::t('Updated') . "<br/>" . Module::t('Go to list of') . " " . Html::a(Module::t('Not translated'), '/translations/index?SourceMessageSearch[message]=&SourceMessageSearch[category]=&SourceMessageSearch[status]=2') . " " . Module::t('Or') . " " . Html::a(Module::t('All'), '/translations/index'), 'options' => ['class' => 'alert-success']]); return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }
示例#18
显示文件
文件: DefaultController.php 项目: wancer/yii2-i18n-module
/** * @param integer $id * @return string|Response */ public function actionUpdate($id) { /** @var SourceMessage $model */ $model = $this->findModel($id); $model->initMessages(); if (Model::loadMultiple($model->messages, Yii::$app->getRequest()->post()) && Model::validateMultiple($model->messages)) { $model->saveMessages(); Yii::$app->getSession()->setFlash('success', Module::t('Updated')); return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }
示例#19
显示文件
文件: TranslationController.php 项目: metalguardian/yii2-i18n-module
/** * Updates an existing SourceMessage model. * If update is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $model->populateMessages(); if (Model::loadMultiple($model->messages, Yii::$app->request->post())) { $model->linkMessages(); if (Model::validateMultiple($model->messages)) { Yii::$app->getSession()->setFlash('success', Module::t('Translation successfully updated')); return $this->redirect(['index']); } } return $this->render('update', ['model' => $model]); }
示例#20
显示文件
文件: VariationBehavior.php 项目: yii2tech/admin
/** * Handles `afterDataLoad` event. * Populates the variation models with input data. * @param ActionEvent $event event instance. */ public function afterDataLoad($event) { if (!$event->result) { return; } $model = $event->model; $data = Yii::$app->request->post(); foreach ($this->getVariationModelBatches($model) as $variationName => $variationModels) { if (!Model::loadMultiple($variationModels, $data)) { $event->result = false; return; } } }
示例#21
显示文件
文件: ViewController.php 项目: dench/resistor
/** * Updates an existing View 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); for ($i = 1; $i <= Lang::find()->count(); $i++) { $model_content[$i] = ViewLang::findOne(['id' => $id, 'lang_id' => $i]); } if (Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content)) { foreach ($model_content as $key => $content) { $content->save(false); } return $this->redirect(['/view']); } else { return $this->render('update', ['model' => $model, 'model_content' => $model_content]); } }
示例#22
显示文件
文件: SettingsController.php 项目: ramialcheikh/quickforms
public function actionMail() { $this->layout = 'admin'; // In @app/views/layouts $settings = Setting::find()->where(['category' => 'smtp'])->orderBy('id')->all(); if (Model::loadMultiple($settings, Yii::$app->request->post()) && Model::validateMultiple($settings)) { /** @var \app\models\Setting $setting */ foreach ($settings as $setting) { $setting->save(false); } // Show success alert Yii::$app->getSession()->setFlash('success', Yii::t('app', 'The smtp server settings have been successfully updated.')); } return $this->render('mail', ['settings' => $settings]); }
示例#23
显示文件
文件: EditController.php 项目: gechet/yii2-title
/** * Обрабатывает данные из формы и русет саму форму */ public function actionIndex() { $rules = Titles::find()->indexBy('id')->all(); $newRule = $this->newTitles(); if ($newRule->load(Yii::$app->request->post()) and !empty($newRule->url) and !empty($newRule->title)) { $newRule->save(); $newRule = $this->newTitles(); } if (Model::loadMultiple($rules, Yii::$app->request->post()) && Model::validateMultiple($rules)) { foreach ($rules as $rule) { $rule->save(false); $rules = Titles::find()->indexBy('id')->all(); } } return $this->render('index', ['rules' => $rules, 'newRule' => $newRule]); }
示例#24
显示文件
文件: EvauateScoreController.php 项目: phisithos/yii2-workshop-co-sapce
/** * Creates a new EvauateScore model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($hospital_id, $group_id = null) { $group_id = $this->loadDefaultGroup($group_id); $models = $this->loadEvauateScoreModels($hospital_id, '2558', $group_id); $sumTheMust = $this->loadSummaryByUser($hospital_id, '2558', $group_id, 1); $sumTheBest = $this->loadSummaryByUser($hospital_id, '2558', $group_id, 2); $sumTheMustLevel1 = $this->loadSummaryLevel($hospital_id, '2558', $group_id, 1, 1); $sumTheBestLevel1 = $this->loadSummaryLevel($hospital_id, '2558', $group_id, 2, 1); if (Model::loadMultiple($models, Yii::$app->request->post()) && Model::validateMultiple($models)) { foreach ($models as $model) { $model->save(false); } return $this->redirect(['evauate-score/create', 'hospital_id' => $hospital_id, 'group_id' => $group_id]); } return $this->render('create', ['models' => $models, 'hospital_id' => $hospital_id, 'group_id' => $group_id, 'sumTheMust' => $sumTheMust, 'sumTheBest' => $sumTheBest]); }
示例#25
显示文件
文件: MessageController.php 项目: dench/resistor
/** * Updates an existing SourceMessage 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); $lang = Lang::find()->all(); foreach ($lang as $i) { $model_content[$i->code] = Message::findOne(['id' => $id, 'language' => $i->code]); } if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content) && $model->save()) { foreach ($model_content as $key => $content) { $content->save(false); } return $this->redirect(['/message']); } else { return $this->render('update', ['model' => $model, 'model_content' => $model_content]); } }
示例#26
显示文件
文件: PurchaseRequest.php 项目: wenlife207/yii2-school-project
/** * [通过POST数据载入附表的数据] * 该方法用于新建和修改时返回的POST数据 * 新建时:需要创建数据来接受多条返回数据 * 修改时:subdata已经是数组,所以直接能够被模型LOAD,而且如果不这样做,无法实现对isNewRecord的判断 * @param [post] [POST数组] * @return [null] [POST如果没有设置ReqItem] */ public function loadSubData($post) { if (isset($post['ReqItem'])) { //如果是新建,则要组建数组 if (!is_array($this->subData)) { $itemSum = count($post['ReqItem']); $reqItems = array(); for ($i = 0; $i < $itemSum; $i++) { $reqItems[] = new ReqItem(); } $this->subData = $reqItems; } return Model::loadMultiple($this->subData, $post) && Model::validateMultiple($this->subData); } else { return null; } }
示例#27
显示文件
文件: BlogPostController.php 项目: HeavyDots/heavyCMS
public function actionUpdate($id) { $blogPost = $this->findBlogPost($id); $translations = $blogPost->initializeTranslations(); Model::loadMultiple($translations, $_POST); if ($blogPost->load($_POST) && Model::loadMultiple($translations, $_POST) && Model::validateMultiple($translations) && $blogPost->save()) { $blogPost->saveTranslations($translations); $blogPost->uploadedFeaturedImage = UploadedFile::getInstance($blogPost, 'uploadedFeaturedImage'); if ($blogPost->saveFeaturedImageToDisk()) { Yii::$app->session->setFlash('success', Yii::t('app', 'Blog Post updated successfully')); } else { Yii::$app->session->setFlash('error', Yii::t('app', 'There was some error uploading the blog post Image')); } return $this->redirect(['index']); } return $this->render('update', compact('blogPost', 'translations')); }
示例#28
显示文件
文件: VariationUpdate.php 项目: vall12/admin
/** * @inheritdoc */ public function run($id) { /* @var $model Model|ActiveRecordInterface|\yii2tech\ar\variation\VariationBehavior */ $model = $this->findModel($id); $model->scenario = $this->scenario; $post = Yii::$app->request->post(); if ($model->load($post) && Model::loadMultiple($model->getVariationModels(), $post)) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return call_user_func_array([ActiveForm::className(), 'validate'], array_merge([$model, $model->getVariationModels()])); } if ($model->save()) { $url = array_merge(['view'], Yii::$app->request->getQueryParams(), ['id' => implode(',', array_values($model->getPrimaryKey(true)))]); return $this->controller->redirect($url); } } return $this->controller->render($this->view, ['model' => $model]); }
示例#29
显示文件
文件: DefaultController.php 项目: yarcode/yii2-i18n-yarcode
public function actionSaveTranslate() { if (!Yii::$app->request->post('hasEditable', false)) { return; } //$key = unserialize(Yii::$app->request->post('editableKey', false)); $key = json_decode(Yii::$app->request->post('editableKey', false), true); if (empty($key)) { return; } /** @var Message $model */ $model = Message::findOne($key); if (Model::loadMultiple([Yii::$app->request->post('editableIndex', 0) => $model], Yii::$app->request->post()) && $model->save()) { echo Json::encode(['output' => Html::encode($model->translation)]); } else { echo Json::encode(['message' => 'Ошибки при вводе']); } }
示例#30
显示文件
文件: GradeOneController.php 项目: elevatesolutions/proverbs
/** * Updates an existing GradeOneForm model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($eid) { $models = $this::findGrade($eid); if (Model::loadMultiple($models, Yii::$app->request->post()) && Model::validateMultiple($models)) { $count = 0; foreach ($models as $model) { // populate and save records for each model if ($model->save()) { // do something here after saving $count++; } } Yii::$app->session->setFlash('success', 'Grade saved successfully!'); return $this->render('view', ['models' => $models, 'eid' => $eid]); } else { return $this->render('update', ['models' => $models, 'eid' => $eid]); } }