I have the following rules in my model. The problem is that the custom error message is not displaying. Instead, the default message is displaying. Any idea why that is? I appreciate any help.
public function rules() {
return array(
array('quantity', 'safe'),
array('quantity', 'required'),
array('quantity', 'numerical', 'min'=>1, 'message'=>'{attribute} must be greater than zero.')
);
}
public function rules() {
return array(
array('quantity', 'safe'),
array('quantity', 'required'),
array('quantity', 'numerical', 'message'=>'{attribute} must be greater than zero.')
);
}
public function rules() {
return array(
array('quantity', 'safe'),
array('quantity', 'required'),
array('quantity', 'numerical')
array('quantity', 'length', 'min'=>2, 'message'=>'{attribute} must be greater than zero.')
);
}
public function rules() {
return array(
array('quantity', 'numerical', 'min'=>'1', 'tooSmall'=>'{attribute} must be greater than zero.'),
array('quantity', 'required'),
// array('quantity', 'safe'), <- this is not needed unless on a specific scenario, like 'search'
);
}
I looked up the documentation for CNumberValidator, and the property that should be set is "tooSmall" instead of "message". The following code solved my problem:
public function rules() {
return array(
array('quantity', 'safe'),
array('quantity', 'required'),
array('quantity', 'numerical', 'min'=>1, 'tooSmall'=>'{attribute} must be greater than zero.')
);
}