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


PHP User::getId方法代码示例

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


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

示例1: signup

 /**
  * Регистрация нового пользователя
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $randLength = mt_rand(6, 9);
         $this->password = Yii::$app->security->generateRandomString($randLength);
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             //$profile = new Profile();
             //$profile->user_id = $user->id;
             //$profile->name = $this->name;
             ////если в куках есть id аффилиата, сохраняем его
             //$affiliateId = (int) Yii::$app->request->cookies['affiliate'];
             //if ($affiliateId > 0 && User::findIdentity($affiliateId)) {
             //$profile->user_affiliate_id = $affiliateId;
             //}
             //$profile->save();
             // Присвоить роль пользователю можно при создании нового пользователя.
             //  присвоить Роль "user" новому пользователю
             // `auth_assignment`
             $userRole = Yii::$app->authManager->getRole('user');
             Yii::$app->authManager->assign($userRole, $user->getId());
             return $this->sendRegistrationEmail();
         }
     }
     return null;
 }
开发者ID:bxgsmart,项目名称:korsun-yii2-web-monitoring,代码行数:35,代码来源:SignupForm.php

示例2: reg

 public function reg()
 {
     $user = new User();
     $user->phone = $this->phone;
     $user->email = $this->email;
     $user->status = $this->status;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     if ($this->scenario === 'emailActivation') {
         $user->generateSecretKey();
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         if ($user->save()) {
             $modelProfile = new Profile();
             $modelProfile->user_id = $user->id;
             if ($modelProfile->save()) {
                 $transaction->commit();
                 return RbacHelper::assignRole($user->getId()) ? $user : null;
             }
         } else {
             return false;
         }
     } catch (Exception $e) {
         $transaction->rollBack();
     }
 }
开发者ID:baranov-nt,项目名称:some-2,代码行数:27,代码来源:RegForm.php

示例3: setModel

 /**
  * @param User $model
  * @return User
  */
 public function setModel($model)
 {
     $this->username = $model->username;
     $this->email = $model->email;
     $this->status = $model->status;
     $this->model = $model;
     $this->roles = ArrayHelper::getColumn(\Yii::$app->authManager->getRolesByUser($model->getId()), 'name');
     return $this->model;
 }
开发者ID:rafalsky,项目名称:home-finance,代码行数:13,代码来源:UserForm.php

示例4: assignRole

 /**
  * Assigns the appropriate role to the registered user.
  * If this is the first registered user in our system, he will get the
  * root role (this should be you), if not, he will get the user role.
  *
  * @param  User   $user User object.
  * @return string       Role name.
  */
 public static function assignRole(User $user)
 {
     $id = $user->getId();
     // make sure there are no leftovers
     Role::deleteAll(['user_id' => $id]);
     $auth = Yii::$app->authManager;
     $role = $auth->getRole($user->user_role);
     $auth->assign($role, $id);
     // return assigned role name in case you want to use this method in tests
     return $role->name;
 }
开发者ID:snivs,项目名称:semanti,代码行数:19,代码来源:RbacHelper.php

示例5: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->save();
         $user->afterSignup();
         $auth = Yii::$app->authManager;
         $auth->revokeAll($user->getId());
         if ($this->roles && is_array($this->roles)) {
             foreach ($this->roles as $role) {
                 $auth->assign($auth->getRole($role), $user->getId());
             }
         }
         return $user;
     }
     return null;
 }
开发者ID:Sywooch,项目名称:AVSProduct,代码行数:25,代码来源:SignupForm.php

示例6: signup

 /**
  * Signs up the user.
  * If scenario is set to "rna" (registration needs activation), this means
  * that user need to activate his account using email confirmation method.
  *
  * @return User|null The saved model or null if saving fails.
  */
 public function signup()
 {
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     $user->status = $this->status;
     // if scenario is "rna" ( Registration Needs Activation ) we will generate account activation token
     if ($this->scenario === 'rna') {
         $user->generateAccountActivationToken();
     }
     // if user is saved and role is assigned return user object
     return $user->save() && RbacHelper::assignRole($user->getId()) ? $user : null;
 }
开发者ID:firdows,项目名称:yii2-advanced-template,代码行数:22,代码来源:SignupForm.php

示例7: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return string|\yii\web\Response
  */
 public function actionCreate()
 {
     $user = new User(['scenario' => 'create']);
     $role = new Role();
     if ($user->load(Yii::$app->request->post()) && $role->load(Yii::$app->request->post()) && Model::validateMultiple([$user, $role])) {
         $user->setPassword($user->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $role->user_id = $user->getId();
             $role->save();
         }
         return $this->redirect('index');
     } else {
         return $this->render('create', ['user' => $user, 'role' => $role]);
     }
 }
开发者ID:komsin,项目名称:yiiexpert1,代码行数:22,代码来源:UserController.php

示例8: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $userRole = Yii::$app->authManager->getRole('user');
             Yii::$app->authManager->assign($userRole, $user->getId());
             return $user;
         }
     }
     return null;
 }
开发者ID:unix-admin,项目名称:webdev,代码行数:21,代码来源:SignupForm.php

示例9: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->save(false);
         // the following three lines were added:
         $auth = Yii::$app->authManager;
         $authorRole = $auth->getRole('author');
         $auth->assign($authorRole, $user->getId());
         return $user;
     }
     return null;
 }
开发者ID:asadovkamran,项目名称:etap_backup,代码行数:22,代码来源:SignupForm.php

示例10: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->parent_id = $this->parent_id;
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->save(false);
         // нужно добавить следующие три строки:
         $auth = Yii::$app->authManager;
         $userRole = $auth->getRole('user');
         $auth->assign($userRole, $user->getId());
         return $user;
     }
     return null;
 }
开发者ID:lampyris,项目名称:referral,代码行数:23,代码来源:SignupForm.php

示例11: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->acceso_externo = false;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             // Aca es donde se asigna el rol "sinRol" a los nuevos usuarios
             $auth = Yii::$app->authManager;
             $sinRol = $auth->getRole('sinRol');
             $auth->assign($sinRol, $user->getId());
             return $user;
         }
     }
     return null;
 }
开发者ID:ibergonzi,项目名称:country,代码行数:24,代码来源:SignupForm.php

示例12: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return string|\yii\web\Response
  */
 public function actionCreate()
 {
     $user = new User(['scenario' => 'create']);
     if (!$user->load(Yii::$app->request->post())) {
         return $this->render('create', ['user' => $user]);
     }
     $user->setPassword($user->password);
     $user->generateAuthKey();
     if (!$user->save()) {
         return $this->render('create', ['user' => $user]);
     }
     $auth = Yii::$app->authManager;
     $role = $auth->getRole($user->item_name);
     $info = $auth->assign($role, $user->getId());
     if (!$info) {
         Yii::$app->session->setFlash('error', Yii::t('app', 'There was some error while saving user role.'));
     }
     return $this->redirect('index');
 }
开发者ID:firdows,项目名称:yii2-advanced-template,代码行数:25,代码来源:UserController.php

示例13: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->first_name = $this->first_name;
         $user->last_name = $this->last_name;
         $user->username = $this->username;
         $user->email = $this->email;
         $user->avatar = $this->avatar;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             /* Give  user access to client area */
             $auth = Yii::$app->authManager;
             $authorRole = $auth->getRole('client');
             $auth->assign($authorRole, $user->getId());
             return $user;
         }
     }
     return null;
 }
开发者ID:nym3ny,项目名称:westwolf,代码行数:26,代码来源:SignupForm.php

示例14: fillUserData

 /**
  * Заполнение данных пользователя.
  *
  * @param User $user
  */
 public function fillUserData(User $user)
 {
     $this->setUserId($user->getId());
     $this->setCompanyId($user->getCompanyId());
     $this->setEmail($user->getEmail());
     $this->setFullName($user->getFullName());
     $this->setRole($user->getRole());
     $this->setStatus($user->getStatus());
     $this->setPhoto($user->getPhoto());
 }
开发者ID:vlamug,项目名称:landing-page-crm,代码行数:15,代码来源:ProfileForm.php


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