Whenever create a model using gii CRUID, it automatically generate for us all functions we need: edit, delete, create, read, also the form. Did you ever wonder how can it display the error message when we do a wrong form submit ? How could we customize that error message ?
The key is
_form.php,
we will see the code which help us display the error message.
<?php echo $form->error($model,'post_title'); ?>
The point is how can we customize the message display when it’s wrong with validation rule.
class Post extends CActiveRecord { public function rules() { return array( array('post_title', 'required', 'message'=>'Please enter a value for {attribute}.'), ); } }
In this code above, line 7, there is a predefined placeholder {attribute}. The CRequiredValidator will replace the actual attribute name that fails the validation.