當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::validate方法代碼示例

本文整理匯總了PHP中frontend\models\User::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::validate方法的具體用法?PHP User::validate怎麽用?PHP User::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在frontend\models\User的用法示例。


在下文中一共展示了User::validate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionSignIn

 public function actionSignIn()
 {
     $model = new User();
     $model->scenario = $model::SCENARIO_SIGN_IN;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
     }
     return $this->render('sign-in', ['model' => $model]);
 }
開發者ID:Youxiang11,項目名稱:product,代碼行數:8,代碼來源:UserController.php

示例2: actionEdit

 public function actionEdit()
 {
     $model = new UserModel();
     $model->scenario = 'edit';
     $user = Yii::$app->user->identity->getAttributes();
     $model->setAttributes($user, false);
     $serviceName = Yii::$app->getRequest()->getQueryParam('service');
     if (isset($serviceName)) {
         $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
         $eauth->setRedirectUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('profile/edit'));
         $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('profile/edit'));
         try {
             if ($eauth->authenticate()) {
                 $attributes = User::getResponseEAuth($eauth);
                 // BIND SOCIAL ID
                 if (!empty($attributes['field']) && !empty($attributes['userId'])) {
                     $user = User::findOne($user['id']);
                     $user->load(['User' => [$attributes['field'] => $attributes['userId']]]);
                     $user->save();
                     Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Profile successfully changed'));
                 }
                 // UPLOAD SOCIAL AVATAR
                 $imageUrl = $attributes['photo'];
                 if ($imageUrl) {
                     $filename = User2Image::copySocialImage($imageUrl);
                     $image = new User2Image();
                     $image->user_id = $user['id'];
                     $image->main_image = $filename;
                     $image->images = ['0' => $filename];
                     if (User2Image::hasImages($user['id'])) {
                         $db = Yii::$app->db;
                         $db->createCommand("UPDATE user_2_image SET is_main=0 WHERE user_id = {$user['id']}")->query();
                     }
                     $image->addImages();
                 }
                 return $eauth->redirect();
             } else {
                 return $eauth->redirect($eauth->getCancelUrl());
             }
         } catch (\nodge\eauth\ErrorException $e) {
             Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
             return $eauth->redirect($eauth->getCancelUrl());
         }
     }
     // IMAGES
     list($images, $mainImage) = User2Image::existsImages(Yii::$app->user->identity->id);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->save();
         Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Profile successfully changed'));
         return $this->redirect(['/profile']);
     } else {
         return $this->render('edit', ['model' => $model, 'images' => $images, 'mainImage' => $mainImage, 'user' => $user]);
     }
 }
開發者ID:beatom,項目名稱:exampleYii2,代碼行數:54,代碼來源:ProfileController.php


注:本文中的frontend\models\User::validate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。