本文整理汇总了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]);
}
示例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: 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' => '']);
}
示例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;
}
示例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]);
}
示例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]);
}
}
示例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';
}
}
示例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;
}
示例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)];
}
示例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]);
}
示例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'));
}
示例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'));
}
示例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: 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]);
}
示例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]);
}