common\models\User::getId PHP Method

getId() public method

public getId ( )
    public function getId()
    {
        return $this->getPrimaryKey();
    }

Usage Example

 /**
  * Регистрация нового пользователя
  *
  * @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;
 }
All Usage Examples Of common\models\User::getId