Validators extending from [CValidator] all have a property named [message|CValidator::message]. You can set this property in the corresponding validation rule to customize the error message. For example, the following validation rule uses an error message that is different from the default one:
class Post extends CActiveRecord
{
public function rules()
{
return array(
array('title, content', 'required',
'message'=>'Please enter a value for {attribute}.'),
// ... other rules
);
}
}
In the above, the customized error message contains a predefined placeholder {attribute}
. The [CRequiredValidator] (whose alias is required
) will replace this placeholder with the actual attribute name that fails the validation.
Missign value
What about the value of the attribute? That is in default error messages. Shouldn't there be a {value} ?
Re: Missing value
No, you SHOULD use {attribute} placeholder.
Look for predefined {attribute} placeholder.
Placeholder values
Here's a list of many placeholders and the validators that are using them:
Of course, {attribute} is known in all validators.
So, which placeholders are known depends on the validator and the condition as well: By default {min} is only used when the value is below the min value (as defined in rules) and {max} when the value is above the max value.
How can customize messages for any rule of File?
About
File
rule, There are more then one rule. some rules is for "types", "allowEmpty", "maxSize",... Now how can customize messages for any rule ofFile
?Answer: Can use "tooLarge", "tooMany", "tooSmall", "wrongMimeType", "wrongType", ... methods.
re: http://www.yiiframework.com/doc/api/1.1/CFileValidator
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.