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


PHP User::getErrors方法代码示例

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


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

示例1: create

 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new User();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = "Create";
             $log->object_class = "User";
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         $model->created_at = $now;
         $model->dob = strtotime($model->dob);
         do {
             $path = FileUtils::generatePath($now);
         } while (file_exists(Yii::$app->params['images_folder'] . $path));
         $model->image_path = $path;
         $targetFolder = Yii::$app->params['images_folder'] . $model->image_path;
         $targetUrl = Yii::$app->params['images_url'] . $model->image_path;
         if (!empty($data['user-image'])) {
             $copyResult = FileUtils::copyImage(['imageName' => $model->image, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'resize' => [[120, 120], [200, 200]], 'resizeType' => 2, 'removeInputImage' => true]);
             if ($copyResult['success']) {
                 $model->image = $copyResult['imageName'];
             }
         }
         // User class
         $model->generateAuthKey();
         $model->setPassword($model->password);
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
开发者ID:quyettvq,项目名称:luspel,代码行数:47,代码来源:User.php

示例2: actionRegister

 /**
  * Register billing account
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/site/register<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for registering user.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     name: string, the user name<br/>
  *     email: string, the user email<br/>
  *     password: string, the user password<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     ack: integer, mark the create result, 1 means create successfully, 0 means create fail<br/>
  *     message: string, if create fail, it contains the error message<br/>
  *     data: array, json array to describe all users detail information<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "name" : "harrysun",
  *     "email" : "harrysun1@augmentum.com.cn",
  *     "company" : "Augmentum",
  *     "phone" : "13027785897",
  *     "captcha" : "123456"
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *    'message': 'Register success.'
  * }
  * </pre>
  */
 public function actionRegister()
 {
     //set language zh_cn when sign up
     \Yii::$app->language = LanguageUtil::LANGUAGE_ZH;
     $data = $this->getParams();
     if (empty($data['name']) || empty($data['email']) || empty($data['company']) || empty($data['phone']) || empty($data['captcha']) || empty($data['position'])) {
         throw new BadRequestHttpException('missing param');
     }
     $phone = $data['phone'];
     $this->attachBehavior('CaptchaBehavior', new CaptchaBehavior());
     $this->checkCaptcha($phone, $data['captcha']);
     $email = mb_strtolower($data['email']);
     $user = User::getByEmail($email);
     if (!empty($user)) {
         //check if user active fail, send email again
         if (!$user->isActivated) {
             $validation = Validation::getByUserId($user->_id);
             return $this->_sendRegistEmail($user->_id, $data, $validation);
         } else {
             throw new InvalidParameterException(['email' => \Yii::t('common', 'unique_feild_email')]);
         }
     }
     $accountId = Account::create($data['company'], $phone, $data['name']);
     $user = new User();
     $user->email = $email;
     $user->position = $data['position'];
     $user->accountId = $accountId;
     $user->role = User::ROLE_ADMIN;
     $user->isActivated = User::NOT_ACTIVATED;
     $user->avatar = Yii::$app->params['defaultAvatar'];
     $user->language = LanguageUtil::DEFAULT_LANGUAGE;
     if ($user->save()) {
         return $this->_sendRegistEmail($user->_id, $data);
     } else {
         Account::deleteAll(['_id' => $accountId]);
         if ($user->getErrors('email')) {
             throw new InvalidParameterException(['email' => \Yii::t('common', 'unique_feild_email')]);
         }
         throw new ServerErrorHttpException('regist fail');
     }
 }
开发者ID:timelessmemory,项目名称:uhkklp,代码行数:81,代码来源:SiteController.php


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