Differences between m () and D () methods in thinkphp
Source: Internet
Author: User
Differences between D () and M () methods: The main difference between D and M is that
The m method does not need to create a model class file, and the M method does not read the model class. By default, automatic verification is invalid, but it can be implemented through dynamic assignment.
The D method must have a model class.
We can use the following two methods to create a data table ing object
First: $ test = D ('test ') Type 2: $ test = new model ('test ') Both of them can perform select, insert, delete, and udpate operations on data.
There are big differences in data verification,
In the first method, the data check function is provided for a model instance. If the title is not entered, the system prompts "Enter the title" (this is an automatic verification function provided by TP, of course, you also need to define the verification conditions in the corresponding model );
If the second method is used, there will be no ·····
Another difference is that after $ truetablename is used, $ test = D ('test') must be used to query the test table,
If $ test = m ('test') is used, the queried data edge is think_test.
Thinkphp2.0 has such problems during the test.
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