Analyze the difference between M() and D() methods in thinkphp_PHP tutorial

WBOY
Release: 2016-07-21 15:04:31
Original
938 people have browsed it

The difference between D() and M() methods:
The main difference between D and M is that
M method does not need to create a model class file, M method The model class will not be read, so automatic verification is invalid by default, but it can be achieved through dynamic assignment
and the D method must create a model class.
We can use the following two methods to create a mapping object of a data table
The first one: $Test = D('Test')
The second one: $Test = new Model('Test')
Although both can perform select, insert, delete, and udpate operations on data, there is a big difference in
data verification.
Use the first In this way, a model will have a data check function. If the title is not filled in, it will prompt "Please enter the title" (this is an automatic verification function provided by TP, of course, the verification conditions also need to be defined in the corresponding model);
If you use the second method, it will be gone...
There is another difference: when $trueTableName is used, $test=d('test') must be used, which means that the test table is queried ,
If $test=m('test') is used, it means that the data side of the query is think_test.
thinkphp2.0 version test has the above problems

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327757.htmlTechArticleThe difference between D() and M() methods: The main difference between D and M is that the M method does not require the creation of a model Class file, the M method will not read the model class, so automatic verification is invalid by default, but it can...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!