<?php
class OwnValidate extends CValidator
{
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param CModel $object the object being validated
* @param string $attribute the attribute being validated
*/
protected function validateAttribute($object,$attribute)
{
if(time() >= $value=$object->$attribute){
$this->addError($object,$attribute,'过期时间不能小于当前时间!');
}
}
/**
* Returns the JavaScript needed for performing client-side validation.
* @param CModel $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @return string the client-side validation script.
* @see CActiveForm::enableClientValidation
*/
public function clientValidateAttribute($object,$attribute)
{
$condition = "((new Date()).getTime() >= (new Date(value).getTime()))";
return "
if(".$condition.") {
messages.push(".CJSON::encode('过期时间不能小于当前时间!').");
}
";
}
}
?>
转载于:https://my.oschina.net/phper1234/blog/205462