class UserPtsValidator extends CValidator
{
public $naming_pts=100;
public $allowEmpty=true;
protected function validateAttribute($object,$attribute)
{
$value=$object->$attribute;
if($this->allowEmpty && ($value===null || $value===''))
return;
if ($value<$this->naming_pts)
$message=$this->message!==null?$this->message:Yii::t('yii','test343434343');
$this->addError($object,$attribute,$message);
}
}
以上代码,当form里面提交的userpts小于100的时候会显示error message,但是当大于等于100的时候就会报错。错误信息Undefined variable: message,错误出现在$this->addError($object,$attribute,$message); 我看了其他的几个validator,好像都是这么写的。btw,我的这个validator的php放在了components目录下。