Yii Cmodel in the rules validation get error message, Yiicmodel
defined in model Public function rules () { return array(' name,email ', ' required '), Array(' Email ', ' unique ', ' message ' = ' {value} ' ERROR '),//{value} is the added data ); } Use $modelnew MyModel () in the controller; // to instantiate a model class for a related table $model $_post // The attributes assignment is the data that is submitted (need to be verified), and the field is safe in rules $model->validate (); // The validation rule rules are automatically invoked here $model->geterrors (); // get error messages for all validation fields $model->geterrors (' Email '); // gets the error message for the current incoming field $model->geterror (' Email '); // ' Message message '
How Yii gets the wrong form information and saves it in a string
This with
Chtml::errorsummary ($model 1)
You can check the manual, and his return is a string.
Yii form error message in which file
Your question description is not very clear, I will give you the Yii form verification!
Yii form validation You can refer to the Sitecontroller actioncontact method of the blog in its 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[' AdminEmail '), $model->subject, $model->body, $headers);
Yii::app ()->user->setflash (' Contact ', ' Thank "for contacting us. We'll respond to as soon as possible. ');
$this->refresh ();
}
}
$this->render (' Contact ', array (' model ' = $model));
}
I will not list the part of the model here, see its demo inside it!
This method is after the form is submitted
if (Isset ($_post[' contactform ')) determines whether the form submits the status of the
$model->attributes=$_post[' contactform '); Assign form data to the Model property
if ($model->validate ()) This step is to call the model inside the validation, if there is an error will return an error, so that the view will be reloaded, so that the view inside the error portion of the form will be wrong output!
Errorsummary ($model);?>
This part comes from the wrong output part of the view!
http://www.bkjia.com/PHPjc/863231.html www.bkjia.com true http://www.bkjia.com/PHPjc/863231.html techarticle Yii Cmodel Rules validation gets error message, Yiicmodel defines public function rules () {return array (' Name,email ', ' required ') in model , Array (' Email ', ' unique ', ' message ' ...