'error.{attribute}_required'], [['username'], 'validateUsername'], ]); } public function validateUsername($attribute) { $account = new Account(); $account->username = $this->$attribute; if (!$account->validate(['username'])) { $this->addErrors($account->getErrors()); } } public function change() { if (!$this->validate()) { return false; } $account = $this->getAccount(); $account->username = $this->username; return $account->save(); } }