In this case error handling is at controller level (login process), so in my humble opinion is more correct to handle this in controller and then pass value to view.
It is controller level, yes, but passing value to view and then doing some more coding to show in view is an overhead if you ask me. The addError function already exists and the framework already allows for it to display messages on the view based on a field.
It will be a nice feature to have in the next release if the addError function could be used without specifying any field attribute.
hi, you can do that by adding custom validation in rules
example
class LoginForm exdtends Model
{
public $username,$password;
public function rules()
{
return [
[['username', 'password'], 'myValidator'],
];
}
public function myValidator($attribute, $params)
{
$this->addError($attribute, 'Incorect username or password');
}
}
Thanks, but that will not work. It will mark the password field as red and give the error message. I don’t want any fields marked because it must be a general error.