/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new Customer(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { return $user; } } return null; }
/** * Finds user by [[username]] * * @return User|null */ public function getCustomer() { if ($this->_customer === false) { $this->_customer = Customer::findByUsername($this->username); } return $this->_customer; }
/** * 一对一 */ public function getCustomer() { return $this->hasOne(Customer::className(), ['id' => 'customer_id']); }