Yii framework2.0 development tutorial (7) account registration and development

Source: Internet
Author: User
Tags yii

Registration process: user input data-> submit server-> insert Database

Because ar inherits from [[yii \ base \ model], it also supports data input, verification, and other features of the model. For example, you can declare a rules method to overwrite the rules in [[yii \ base \ model: Rules () | rules; you can also assign values to Ar instances in batches. You can also call [[yii \ base \ model: Validate () | validate ()] to perform data verification.

When you call the SAVE (), insert (), update () methods, [[yii \ base \ model: Validate () | validate ()] method. If the verification fails, the data will not be saved to the database.

The following example demonstrates how to use AR to obtain/verify user input data and save them to the database:

// Create a new record $ model = new customer; if ($ model-> load (yii ::$ app-> request-> post ()) & $ model-> Save () {// [retrieve user input data ], verify and save.} // update the AR $ model = Customer: findone ($ id) with the primary key of $ id. If ($ model = NULL) {Throw new notfoundhttpexception;} if ($ model-> load (yii: $ app-> request-> post () & $ model-> Save ()) {// obtain user input data, verify and save}


Reference: https://github.com/yiisoft/yii2/blob/master/docs/guide-zh-CN/db-active-record.md#%E6%95%B0%E6%8D% AE %E8%BE%93%E5%85%A5%E4%B8%8E%E6%9C%89%E6%95%88%E6%80%A7%E9%AA%8C%E8%AF%81


Reprinted please indicate the source: http://blog.csdn.net/zhyoulun/article/details/40476689

Yii framework2.0 development tutorial (7) account registration and development

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.