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


PHP ActiveForm::validate方法代码示例

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


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

示例1: performValidationModel

 /**
  * Performs ajax validation.
  *
  * @param \yii\base\Model $model
  *
  * @throws \yii\base\ExitException
  */
 protected function performValidationModel(Model $model)
 {
     if ($model->load(Yii::$app->request->post())) {
         return ActiveForm::validate($model);
     }
     return;
 }
开发者ID:ostashevdv,项目名称:brick,代码行数:14,代码来源:AjaxValidation.php

示例2: run

 /**
  * VISTA PUBLICAR ARTICULO
  * @return string
  */
 public function run()
 {
     $session = Yii::$app->session;
     $idUsuario = Yii::$app->user->getId();
     $claveSession = ImagenHelper::SESSION_IMAGEN_ARTICULO . $idUsuario;
     $model = new CrearEditarDescuentoForm();
     $model->scenario = CrearEditarDescuentoForm::ESCENARIO_CREAR;
     $model->usuario = $idUsuario;
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($session->has($claveSession)) {
             $files = $session->get($claveSession);
             $model->imagenes = $files['file'];
             $model->principal = Yii::$app->request->post('dropzone_imagen_principal');
         }
         if ($model->crear()) {
             // file is uploaded successfully
             $session->remove($claveSession);
             //Toast::widget(['tipo'=>'success', 'mensaje'=>'Se ha creado la categor�a con �xito']);
             Yii::$app->session->setFlash('success', 'Se ha creado la categoria con exito');
             return $this->controller->redirect('/');
             $data = 'Se ha publicado';
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return $data;
         }
     } else {
         $session->remove($claveSession);
         return $this->controller->render('publicar-descuento', ['model' => $model]);
     }
 }
开发者ID:alejandrososa,项目名称:AB,代码行数:37,代码来源:PublicarAction.php

示例3: actionEdit

 public function actionEdit($id)
 {
     if (!($model = Item::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['articleThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'sections');
                 } else {
                     $model->image = $model->oldAttributes['image'];
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/sections', 'Article updated'));
                 return $this->redirect(['/admin/' . $this->module->id . '/items/edit', 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }
开发者ID:engmohamedamer,项目名称:testone,代码行数:30,代码来源:ItemsController.php

示例4: actionCrear

 /**
  * Creates a new Usuarios model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCrear()
 {
     $model = new CrearUsuarioForm();
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->setPassword($model->clave_hash);
         $model->generateAuthKey();
         $model->tipo = Usuarios::ES_VISITA;
         $model->save();
         $archivo_tmp_original = Yii::getAlias('@backend') . '/web/' . str_replace(".", '-original.', $model->imagen_nombre);
         $archivo_tmp = Yii::getAlias('@backend') . '/web/' . $model->imagen_nombre;
         $imagen_nombre = $model->idusuario . '_' . uniqid() . '.png';
         $ruta = Yii::getAlias('@common') . '/imagenes/usuarios/' . $imagen_nombre;
         $data = base64_decode($model->imagen_data);
         file_put_contents($ruta, $data);
         if (file_exists($ruta)) {
             $imgModel = Usuarios::find()->where(['idusuario' => $model->idusuario])->one();
             $imgModel->foto = $imagen_nombre;
             $imgModel->save();
             if (file_exists($archivo_tmp)) {
                 unlink($archivo_tmp);
                 unlink($archivo_tmp_original);
             }
         }
         return $this->redirect(['detalle/' . $model->idusuario]);
     } else {
         return $this->render('crear', ['model' => $model]);
     }
 }
开发者ID:alejandrososa,项目名称:AB,代码行数:37,代码来源:UsuariosController.php

示例5: run

 public function run()
 {
     $request = Yii::$app->request;
     $user = Yii::createObject($this->modelClass, ['scenario' => $this->scenario]);
     $profile = Yii::createObject($this->profileClass);
     $roles = [];
     if ($this->roleArray !== null) {
         $roles = call_user_func($this->roleArray, $this);
     }
     $roleArray = ArrayHelper::map($roles, 'name', 'description');
     $statusArray = [];
     if ($this->statusArray !== null) {
         $statusArray = call_user_func($this->statusArray, $this);
     }
     if ($user->load($request->post()) && $profile->load($request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 $this->trigger('success', new Event(['data' => $user]));
                 return $this->controller->redirect(Url::to([$this->updateRoute, 'id' => $user->id]));
             } else {
                 $this->trigger('success', new Event(['data' => Module::t('admin', 'Failed create user')]));
                 return $this->controller->refresh();
             }
         } elseif ($request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
         }
     }
     return $this->render(compact(['user', 'profile', 'roleArray', 'statusArray']));
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:31,代码来源:CreateAction.php

示例6: actionCreate

 /**
  * Creates a new Staff model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('admin')) {
         $model = new Staff();
         if (Yii::$app->request->isAjax && $model->load($_POST)) {
             Yii::$app->response->format = 'json';
             return \yii\widgets\ActiveForm::validate($model);
         }
         if ($model->load(Yii::$app->request->post())) {
             $user = new Users();
             $user->usertype = 'Staff';
             $user->password = strtolower($model->apellido1 . substr($model->rut, 5, -2));
             $user->email = $model->correo;
             $model->save();
             $user->id_orig = $model->id;
             $user->username = $model->nombre . " " . $model->apellido1;
             $user->save();
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
开发者ID:godzukison,项目名称:mngrApp,代码行数:30,代码来源:StaffController.php

示例7: performAjaxValidation

 /**
  * Performs ajax validation.
  * @param Model $model
  */
 protected function performAjaxValidation(Model $model)
 {
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
 }
开发者ID:just-leo,项目名称:cardgame-serial,代码行数:11,代码来源:AjaxValidationTrait.php

示例8: run

 /**
  * @param string $back
  * @return string
  */
 public function run($back = null)
 {
     if (!Yii::$app->user->isGuest) {
         if ($back) {
             return Yii::$app->response->redirect($back);
         }
         return $this->controller->goHome();
     }
     /** @var AuthLoginFormInterface|Model $model */
     $model = Yii::createObject($this->modelClass);
     $postData = Yii::$app->request->post();
     if ($model->load($postData)) {
         $request = Yii::$app->request;
         if ($request->isAjax && !$request->isPjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
         if ($model->login()) {
             if ($back) {
                 return Yii::$app->response->redirect($back);
             }
             return $this->controller->goBack();
         }
     }
     return $this->controller->render($this->viewName, ['model' => $model]);
 }
开发者ID:voskobovich,项目名称:yii2-auth-toolkit,代码行数:30,代码来源:LoginAction.php

示例9: run

 public function run()
 {
     /** @var User $user */
     $user = Yii::$app->user->identity;
     if ($user === null) {
         throw new ServerErrorHttpException("No user identity found");
     }
     $user->setScenario(User::SCENARIO_PROFILE_UPDATE);
     if ($user->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             // perform AJAX validation
             echo ActiveForm::validate($user);
             Yii::$app->end();
             return '';
         }
         if ($user->username_is_temporary && count($user->getDirtyAttributes(['username'])) === 1) {
             $user->username_is_temporary = false;
         }
         if ($user->save()) {
             $returnUrl = RedirectHelper::getPostedReturnUrl();
             if ($returnUrl !== null) {
                 return $this->controller->redirect($returnUrl);
             } else {
                 Yii::$app->session->setFlash('success', Yii::t('users', 'Your profile sucessfully updated.'));
             }
         }
     }
     return $this->controller->render($this->viewFile, ['profileWidgetOptions' => $this->profileWidgetOptions, 'user' => $user]);
 }
开发者ID:cheaterBY,项目名称:yii2-users-module,代码行数:30,代码来源:Profile.php

示例10: run

 /**
  * Create Record model or update an existing Record model. Create Files and attach to Record model.
  * If update is successful, the browser will be redirected to the 'upload' page.
  * @return array|string|Response
  * @throws \yii\web\NotFoundHttpException
  */
 public function run()
 {
     $recordId = Yii::$app->request->get('id');
     if ($recordId) {
         $model = $this->controller()->findModel(Record::className(), $recordId);
     } else {
         $model = new Record();
         $model->scenario = Record::SCENARIO_UPLOAD;
     }
     $model->user_id = Yii::$app->user->id;
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     $post = Yii::$app->request->post();
     if ($model->load($post) && $model->validate()) {
         if ($this->saveRecord($model, $post)) {
             Yii::$app->trigger(EventNames::UPLOAD_SUCCESS, new UploadEvent(['record' => $model, 'user_id' => Yii::$app->user->id]));
         }
         return $this->controller()->redirect(['upload', 'id' => $model->id]);
     }
     $media = self::media();
     $uploadUrl = $media->uploadRoute;
     $handleUrl = $media->handleRoute;
     $dropZone = $media->dropZone;
     $maxFileSize = $media->maxFileSize;
     $maxChunkSize = $media->maxChunkSize;
     $acceptMimeTypes = $media->acceptMimeTypes;
     $view = $recordId ? 'edit' : 'upload';
     return $this->controller()->render($view, ['model' => $model, 'handleUrl' => $handleUrl, 'uploadUrl' => $uploadUrl, 'dropZone' => $dropZone, 'maxFileSize' => $maxFileSize, 'maxChunkSize' => $maxChunkSize, 'acceptMimeTypes' => $acceptMimeTypes]);
 }
开发者ID:vfokov,项目名称:tims2,代码行数:37,代码来源:UploadAction.php

示例11: run

 /**
  * @inheritdoc
  */
 public function run()
 {
     $request = Yii::$app->getRequest();
     $modelClass = $this->modelClass === null ? $this->controller->modelClass : $this->modelClass;
     //找到当前模型的所有主键,拼接成数组条件
     $pks = $modelClass::primaryKey();
     $pkValues = [];
     $requestMethod = $request->isGet ? 'get' : 'post';
     foreach ($pks as $pk) {
         $pkValues[$pk] = $request->{$requestMethod}($pk);
     }
     $from = $request->{$requestMethod}('from');
     $model = $modelClass::findOne($pkValues);
     if ($model === null) {
         throw new NotFoundHttpException('没有找到相应的记录!');
     }
     $model->scenario = $this->scenario;
     //如果是提交数据则尝试保存
     if ($model->load($request->post())) {
         if (false !== $model->save()) {
             return $this->controller->flash(['message' => $this->successMsg, 'url' => $from]);
         } elseif ($request->isAjax) {
             //如果是ajax请求则返回错误信息而不是直接跳转到原页面
             $errors = ActiveForm::validate($model);
             return $this->controller->flash(['type' => 'error', 'message' => $this->errorMsg, 'time' => 3000, 'data' => ['errors' => $errors]]);
         }
     }
     //获取当前模型的控件属性
     $controlAttributes = method_exists($model, 'controlAttributes') ? $model->controlAttributes() : [];
     //\yii\helpers\VarDumper::dump($model, 10, true);
     return $this->controller->render($this->view, ['controlAttributes' => $controlAttributes, 'get' => $request->get(), 'model' => $model, 'pks' => $pks, 'from' => $from]);
 }
开发者ID:phpdn,项目名称:qc-base,代码行数:35,代码来源:UpdateAction.php

示例12: actionValidatebuy

 public function actionValidatebuy()
 {
     $model = new StackTransaction();
     $stack = Stack::findOne(Yii::$app->request->get('id'));
     if ($model->load(Yii::$app->request->post())) {
         $data = Yii::$app->request->post();
         $result = ActiveForm::validate($model);
         $model->price = $stack->price;
         $model->member_id = Yii::$app->user->identity->id;
         $model->stack_id = $stack->id;
         $model->type = 0;
         $model->total_price = $model->price * $model->volume;
         if ($data['StackTransaction']['password2'] && Yii::$app->user->identity->validatePassword2($data['StackTransaction']['password2'])) {
             $model->addError('password2', '第二密码不正确, 请确认后重新输入.');
         }
         if ($model->account_type == 1 && Yii::$app->user->identity->finance_fund < $model->total_price || $model->account_type == 2 && Yii::$app->user->identity->stack_fund < $model->total_price) {
             if (Yii::$app->user->identity->finance_fund < $model->total_price) {
                 $model->addError('volume', '账户余额不足. 理财基金:.' . Yii::$app->user->identity->finance_fund . '. 购股账户:' . Yii::$app->user->identity->stack_fund);
             }
         }
         foreach ($model->getErrors() as $attribute => $errors) {
             $result[Html::getInputId($model, $attribute)] = $errors;
         }
         Yii::$app->response->format = Response::FORMAT_JSON;
         echo json_encode(ActiveForm::validate($model));
     } else {
         echo json_encode(array());
     }
     Yii::$app->end();
 }
开发者ID:cindyming,项目名称:yii-advance,代码行数:30,代码来源:StackController.php

示例13: run

 /**
  * Delete user page.
  *
  * @param integer $id User ID
  *
  * @return mixed View
  */
 public function run($id)
 {
     $request = Yii::$app->request;
     $user = $this->findModel($id);
     $user->scenario = $this->scenario;
     $profile = $user->{$this->profileRelation};
     $roles = [];
     if ($this->roleArray !== null) {
         $roles = call_user_func($this->roleArray, $this);
     }
     $roleArray = ArrayHelper::map($roles, 'name', 'description');
     $statusArray = [];
     if ($this->statusArray !== null) {
         $statusArray = call_user_func($this->statusArray, $this);
     }
     if ($user->load($request->post()) && $profile->load($request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation($this->profileRelation, $profile);
             if (!$user->save(false)) {
                 $this->trigger('danger', new Event(['data' => $user]));
                 //Yii::$app->session->setFlash('danger', Module::t('admin', 'Failed update user'));
             }
             return $this->controller->refresh();
         } elseif ($request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
         }
     }
     return $this->render(compact(['user', 'profile', 'roleArray', 'statusArray']));
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:37,代码来源:UpdateAction.php

示例14: actionRegister

 public function actionRegister()
 {
     //     	if (!\Yii::$app->user->isGuest) {
     //     		return $this->goHome();
     //     	}
     $model = new RegisterForm();
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model, 'username');
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $user = new User();
             $user->username = $model->username;
             $user->setPassword($model->password);
             $user->email = $model->email;
             $user->name = $model->name;
             $user->surname = $model->surname;
             Yii::trace($user);
             if ($user->save(false)) {
                 return $this->redirect('/user/login');
             }
         }
     }
     return $this->render('register', ['model' => $model]);
 }
开发者ID:michal-cierczek,项目名称:psi,代码行数:26,代码来源:UserController.php

示例15: actionLogo

 public function actionLogo()
 {
     $model = Setting::find()->where(['name' => 'logo'])->one();
     if ($model === null || $model->visibility < (IS_ROOT ? Setting::VISIBLE_ROOT : Setting::VISIBLE_ALL)) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
         return $this->redirect(['/admin/settings']);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_POST['Setting']['value'])) {
                 $model->value = UploadedFile::getInstance($model, 'value');
                 if ($model->value) {
                     $model->value = Image::uploadLogo($model->value, 'logo', false);
                 } else {
                     $model->value = '';
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii', 'Setting updated'));
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('logo', ['model' => $model]);
     }
 }
开发者ID:thedollarsign,项目名称:easyii,代码行数:31,代码来源:SettingsController.php


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