The difference between M of and D of in thinkphp is analyzed

  • 2020-06-15 07:58:13
  • OfStack

Differences between D() and M() methods:
The main difference between D and M is that
The M method does not need to create the model class file, and the M method does not read the model class, so automatic validation is invalid by default, but can be achieved by dynamic assignment
The D method must have the create model class.
We can use the following two methods to create a mapping object for a data table
Type 1: $Test = D('Test')
Type 2: $Test = new Model('Test')
Although the two can be select for data, insert, delete, udpate operation, in
There's a big difference in the validation of the data,
If title does not fill in, it will prompt "please enter the title" (this is an automatic verification function provided by tp, of course, the verification conditions need to be defined in the corresponding model).
If I use the second one, it's gone
Another difference is that when $trueTableName is used, you must use $test=d('test') to indicate that the query is for the test table,
If $test=m('test') is used, then the data edge of the query is think_test.
thinkphp 2.0 version tests have the above problem

Related articles: