$model-addError oddity


Strange problem with CFormModel->addError. I am using a site logon that is based very closely on what is provided "out of the box". Our database of usernames and passwords is used by another service. We have groups of users who have a single "admin" user. Only the admin user can log on to the Yii app; so it was decided that if a non-admin user entered a valid username / password pair, instead of being told that the username or password was wrong, they would be given the name of their admin user, and that this error should appear next to the username field.

In the code below this info is passed back in $this->_identity->explanation.

That is by way of background info.

The problem is this. If you look at the code below, if I assign the error to the ‘username’ attribute, it is not displayed.

I have checked inside login.php that the error is there by looking at getErrors(). I have got it to work by using username_error, as below. But I still want to know why ‘username’ is not working.



public function authenticate($attribute,$params)




			$this->_identity=new UserIdentity($this->username,$this->password);

			if(!$this->_identity->authenticate()) {

				if ($this->_identity->explanation == '') {

					$this->addError('password', 'Incorrect username or password.');

				} else {

					$this->addError('username_error', $this->_identity->explanation ); 






	<div style="visibility: visible;" class="row">

		<?php echo $form->labelEx($model,'username'); ?>

		<?php echo $form->textField($model,'username', array('size'=>40)); ?>

		<?php echo $form->error($model,'username_error'); // see models/LoginForm.php  ?>