Tp makes it difficult to create

Source: Internet
Author: User
Create () is used many times in the create project, which is difficult to understand. it can only be used for form verification, but it is difficult to make mistakes. in this case, I am so sorry to understand the ins and outs of it and how it is used: use the create () method or the value assignment method to generate a data object, and then write it to database 1 $ modelD (User); 2 $ model-& gt; create (); skip the specific automatic generation and verification judgment 3 $ model-& tp makes it difficult to understand the specific create

Create () is used multiple times in the project. it can only be used for form verification. However, it is difficult to understand the ins and outs of the project and its usage.

I. use the create () method or the value assignment method to generate data objects and then write them to the database.

1 $ model = D ('user'); 2 $ model-> create (); // skip the specific automatic generation and verification judgment 3 $ model-> add ()

1: The create () method also supports other methods to create data objects, such as other data objects or arrays.

1 $ data ['name'] = 'Mike '; 2 $ data ['sex'] = 'male'; 3 $ user-> create ($ data );

2. the created data can be directly read and modified.

3: The second operation method of create can specify the operation status of the created data. by default, it automatically determines whether the operation is a write or update operation.

4: If automatic verification is not defined, the return value of the create method is the created data object array.

5: Data objects created by the create method are stored in the memory and not actually written to the database. they are not actually written to the database until the add or save method is used.

2. used in combination with field () and create () to check the validity of a field (form submission)

1 $ model-> field ('title, email, content')-> create ();

Valid fields include title, email, and content. no matter how you add other fields, this will be blocked.

3. automatic verification is a data verification method provided by the model layer. data verification is automatically performed when data objects are created in create: static and dynamic

4. create (): complete a series of work and work processes while creating data objects

Procedure Description Return
1 Obtain the data source (the default is the POST array)
2 Verify the validity of the data source (non-array or the object will be filtered) False is returned for failure.
3 Check field ing
4 Determine the data status (add or edit, specify or automatically determine)
5 Automatic data verification False is returned for failure.
6 Form token verification False is returned for failure.
7 Assignment of form data (filtering illegal fields and string processing)
8 Automatic completion of data
9 Generate data objects (stored in memory)

Related Article

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.