当前位置: 首页>>代码示例>>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;未经允许,请勿转载。