Yii rules use to get error information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.