當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。