Obtain the error message through rules verification in Yii CModel, yiicmodel
Define public function rules () {return array ('name, Email ', 'required'), array ('email', 'unique ', 'message' => '{value} error'), // {value} is the added data);} use $ model = new myModel () in controller (); // instantiate the model class $ model-> attributes = $ _ POST // assign a value to attributes for the data submitted (to be verified, the field is safe $ model-> validate () in rules; // The verification rule rules $ model-> getErrors () is automatically called here (); // get error information of all verification fields $ model-> getErrors ('email '); // get error information of the currently passed field $ model-> getError ('email '); // 'message information'
How does YII get the wrong form information and save it to the string?
Use
CHtml: errorSummary ($ model1)
You can check the manual. The returned result is a string.
In which file is the yii form error message?
Your problem is not clearly described. Let me explain the Yii Form Verification for you!
For Yii form verification, you can refer to the actionContact method of SiteController of blog in demos:
Public function actionContact ()
{
$ Model = new ContactForm;
If (isset ($ _ POST ['contactform'])
{
$ Model-> attributes = $ _ POST ['contactform'];
If ($ model-> validate ())
{
$ Headers = "From: {$ model-> email} \ r \ nReply-To: {$ model-> email }";
Mail (Yii: app ()-> params ['adminmail'], $ model-> subject, $ model-> body, $ headers );
Yii: app ()-> user-> setFlash ('Contact ', 'Thank you for contacting us. We will respond to you as soon as possible .');
$ This-> refresh ();
}
}
$ This-> render ('Contact ', array ('model' => $ model ));
}
I won't list the models here. Let's take a look at them in the demo!
This method is used after the form is submitted.
If (isset ($ _ POST ['contactform']) to determine whether the form is submitted
$ Model-> attributes = $ _ POST ['contactform']; assign the form data to the model attribute.
If ($ model-> validate () is to call the verification in the model. if an error occurs, an error is returned, and the view is reloaded, in this way, the error section in the view will show incorrect output!
<? Php echo $ form-> errorSummary ($ model);?>
This part comes from the error output section in the view!