Creating Data Objects

Source: Internet
Author: User

Create data Object 1, why do you want to create a data object

In the actual project development, often to receive form data, if the form data too much, we need to receive the process through the $_post, in order to simplify the above operation, we can use the data object to solve the problem.

?

Thinkphp can help you create data objects quickly, and the most typical application is to automatically create data objects based on form data, which is especially noticeable in the case of a very high number of fields in a single data table.

2. Simulating the creation of data objects

① changing form data in a add.html template page

② Set drop-down check box

The following is defined in the Add method of the controller:

Traverse through volist in the template:

③ defines a form form that wraps all the form elements as follows:

④ submitting form data using AJAX

⑤ on the server to receive the form data

⑥ the client to determine whether to add success

Question: Why do we not receive any data, just use the Create method and the Add method to complete the receipt of the form and the addition of data?

3, create method detailed

Knowledge points to use: I method

Main function: For receiving form data, equivalent to $_get and $_post

Why use the I method instead of $_get and $_post? Answer: Because I method is more secure.

The Create method is detailed:

If there are no parameters in the Create method, the system receives all the data in the $_post array by default, and then after a series of operations, assigns the returned result to the current object's Data property.

Question: Why is there no parameter in the Add method that can be added normally?

A: The main reason is that the Add method also automatically determines the parameters, as shown in:

Case: Show Department list

① define the Index method in the Dept controller to display the Department list

② Copy the index.html template file to the./application/admin/view/dept folder and change the resource path

③ traversing a list of information in a template file through the Volist method

Creating Data Objects

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.