Reprint Http://blog.sina.com.cn/s/blog_6dcc46a60101c0f2.htmlmodel Use public Function rules () {return Array (arr Ay (' name,email ', ' required '),Array (' Email ', ' unique ', ' message ' = ' {value} ' error '), {value} is the added data);} The controller uses $model = new MyModel ();//Instantiate the related table's model class $model->attributes = $_post//PairThe attributes assignment is the data that is submitted (need to be verified), and the field is safe in rules$model->validate ();//This will automatically invoke the validation rule rules$model->geterrors ();//Get all validation fields
ErrorInformation
Array=>
0 => ' Fname cannot be blank. ' ), ' field ' =>array (0=> ' message '),...) $model->geterrors (' Email ');//Gets the
error message for the current incoming field
array(0 =' Fname cannot be blank. ' )$model->geterror ('Email ');//' Message information ' $form = new Cactiveform (); [Views in $form= $this->beginwidget (' cactiveform ');] Echo $form->errorsummary ($model); Print out all the rules error messages
Yii rules use to get error information