/** * Check the username exist or not * This method serves as the inline validation for username. * * @param string $attribute the attribute currently being validated * @param array $params the additional name-value pairs given in the rule */ public function checkUsernameExists($attribute, $params) { if (!$this->hasErrors()) { if (!User::checkUsernameExist($this->id, $this->username)) { $this->addError($attribute, Yii::t('app', 'This username has already been taken.')); } } }