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?
Page 1 of 1
Method-based validators
#2
Posted 22 July 2010 - 02:47 AM
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.
#3
Posted 22 July 2010 - 04:04 AM
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).
in model:
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')
#4
Posted 22 July 2010 - 04:23 AM
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.
Share this topic:
Page 1 of 1

Help












