Example #1
0
 /**
  * 注册用户。
  * 注册流程需要保存四个模型:
  * - User
  * - Profile
  * - Email
  * - Phone
  * 注册过程可能会抛出异常,而此处不处理异常。
  * 如果注册成功,返回注册用户的ID。
  * 如果不成功,则返回false。
  * @return boolean
  */
 public function register()
 {
     if (!$this->validate()) {
         return false;
     }
     $user = new User(['password' => $this->password, 'type' => User::TYPE_USER]);
     $profile = $user->createProfile(['nickname' => $this->nickname, 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'gender' => $this->gender]);
     $email = $user->createEmail($this->email);
     $phone = $user->createPhone($this->phone);
     $result = $user->register([$profile, $email, $phone]);
     if ($result === true) {
         return $user->id;
     }
     return false;
 }