本文整理汇总了PHP中yii\base\Model::loadMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::loadMultiple方法的具体用法?PHP Model::loadMultiple怎么用?PHP Model::loadMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Model
的用法示例。
在下文中一共展示了Model::loadMultiple方法的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]);
}
示例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]);
}
示例3: 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);
}
}
示例4: 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';
}
}
示例5: 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;
}
示例6: saveMetaTags
/**
* 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: loadWidgetAreas
/**
* 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: actionRequests
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: 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'));
}
示例10: actionCreate
/**
* 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: 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'));
}
示例12: 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]);
}
示例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]);
}
示例14: load
/**
* 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: 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]);
}