Home > Backend Development > PHP Tutorial > ThinkPHP ORM operation and association model_PHP tutorial

ThinkPHP ORM operation and association model_PHP tutorial

WBOY
Release: 2016-07-14 10:10:40
Original
1123 people have browsed it

Object-relational mapping
After the M method quickly instantiates the model, the object directly calls the fields and assigns values. You can directly call the add method to add new ones. Directly call the find method parameter to obtain the current data as the primary key value. Directly call the select method parameter to obtain multiple primary key values. You can obtain each entry data that matches the primary key value. Directly call the find method parameter to the primary key value and directly call its field to change the field value. Directly call the save method to complete the update of a piece of data. Directly call the delete method parameter to the primary key value. value to delete the current data record.


! ! ! ! ! ! ! ! ! Tomorrow's task is to use dynamic record ORM to complete the addition, deletion, modification and search of goods! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !


Verify

The data object created by the create method is stored in memory and is not actually written to the database. It will not be actually written to the database until the add or save method is used. If no value is passed in the create method, $_POST data will be taken by default. If the user submits scalar content, executable HTML code should be filtered manually. Illegal processing can be done using the htmlspecialchars method
The data method is also a method for creating data objects. It also supports passing in arrays and objects. Data objects created using the data method will not be automatically verified and filtered. Illegal data types and non-existent strings will also be automatically filtered.
create() function workflow: obtain the data source, verify the legality of the data source, check field mapping, determine whether the submission status is new or edited, automatic data verification, form token verification, form data assignment, automatic data generation, generated data Object;
Call the custom model and define protected $_validate = array() in the custom model; the array is the verification condition
Array('field name to be verified', 'validation rule', 'prompt' in array(), condition 0 means verification when the field exists, 1 means verification is required, 2 means verification when the data exists!!!!!! Here Still need to study! ! ! There is field uniqueness and the length range is not empty. Password format verification. Judgment is the same. Verification callback function verification


Autocomplete
Also create a protected variable on the custom model side $_auto = array();
In the same array, there is a specific array ('fill field', 'fill rule', fill time 1 is increased, 2 is updated, 3 is all, 'additional rules function callback field string default')


Both of these items will be verified during data validation in the execution of the create method!


In addition, in addition to assigning protected variables on the custom data model side, you can also create data rules in the active segment, call the setProperty method of the model object, assign the previously created data rules to _validate _auto, and finally execute the create method!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477480.htmlTechArticleObject relational mapping M method quickly instantiates the model. After the object directly calls the fields and assigns values, you can directly call the add method to create new ones. Increase, directly call the find method parameter as the primary key value to get the current item...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template