请阅读本文
http://www.yiiframework.com/wiki/1/how-to-customize-the-error-message-of-a-validation-rule/
或者尝试一下
class Post extends CActiveRecord
{
public function rules()
{
return array(
array('title, content', 'required',
'message'=>'Please enter a value for {attribute}.'),
// ... other rules
);
}
}
在上面,自定义的错误消息包含预定义的占位符{attribute}。 CRequiredValidator(需要其别名)将用验证失败的实际属性名称替换此占位符。
如果使用自定义验证函数,则:
class Post extends CActiveRecord
{
public function rules()
{
return array(
array('expire_date_error', 'check'),
);
}
public function check()
{
if($this->a > $this->b) {
$this->addError('expire_date_error', 'New custom error message');
return false;
}
return true;
}
}