Method-based validators

Where I can read more about method-based validators? (Was looking in Guide and Class reference but found nothing.) How do I return an error message if validation is negative?

If you create a webapp you already have an example in protected/models/LoginForm. authenticate is a method based validator. Errors are added with addError() inside such a method.

Thanks a lot!

May I ask you also about class-based validators? I was trying to wite a specific class for validation but it simply… does not validate my data. It allows any value specified (no PHP exception, nothing).


class NUserValidator extends CValidator

{

	public $message = 'This value is not allowed';


	protected function validateAttribute($object, $attribute)

	{

		if (!(NUser::model()->getUserId($object->$attribute)))

			$this->addError($object, $attribute, $this->message);

	}

	

}

in model:


array('authorUsername', 'application.components.validators.NUserValidator')

The class looks o.k. to me. Maybe first hardcode the addError() (like: always add the error, no matter which condition). If this works, check your validation condition.