the difference between M method and D method
The M method and the D method are both used to instantiate a model class, the M method is used to efficiently instantiate an underlying model class, and the D method is used to instantiate a user-defined model class (thinkphp). using the M method
If this is the case, consider using the M method: Use the M method in conjunction with the instantiated Commonmodel class when there are more complex business logic for a simple curd operation of a datasheet without complex business logic
The M method can even simply look at the operation of the data table that corresponds to the parameter table name:
using the D method
If this is the case, consider using the D method: you need to use some of the advanced features in the thinkphp model, such as the Automatic Verification feature (implemented in the Create () method), the association model, and so on, and the many tables involved define the business logic in the custom model class (lib/ Model directory), and want to implement these business logic in the operation
In addition, the D method does not support cross project calls and requires the use of:
$User = D (' User ', ' Admin '); Instantiate the User model under Admin project $User = D (' Admin.user ');
Tips
When project groupings are enabled, the Model class does not necessarily correspond to the grouping of items. The model classes that are common among multiple project groups are uniformly placed under model directories and can be instantiated directly using D (' modelname '). and D (' user.userinfo ') does not mean that the user must be a grouping of items, or just a category of files under model, D (' User.userinfo ') is instantiated in the user directory of the UserInfo model class. Summary
Both the M method and the D method can be used directly without the existence of the model class file, but obviously the M method is more efficient, but you must use the D method to use the business logic within the model class.
A comparative image of the analogy is: M method is like a computer just installed the operating system, only some basic functions, and D method, such as the installed system on the installation of some such as Office, QQ and other applications, more powerful, while the entire computer running speed also slowed.
The above is a summary of the difference between M method and D method, and the M method and D method should be selected according to the actual situation.
(http://blog.163.com/litianyichuanqi@126/blog/static/115979441201223043452383/)
The difference between D () and M () methods:
The difference between D and M is mainly
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 implemented dynamically by assigning a value
The D method must have a Create model class.
We can use the following two ways to create a data table mapping object
First: $Test = D (' Test ')
Second: $Test = new Model (' Test ')
Although both of these can be select,insert,delete,udpate operations on the data, the
There's a big difference in data validation,
The first example of a model will have a data inspection function, if the title is not filled out will prompt "Please enter the title" (This is the TP provides an automatic verification function, of course, also need to be in the corresponding model to define a good validation conditions);
If you do not have this data validation function with the second type, you need to verify it manually.
Summarized as follows:
The D function instantiates the module below the Lib/model of your current project.
If the module does not exist, directly returns the object of the instantiated model (meaning is the same as the M () function).
and M only returns the object that instantiates the model. Its $name parameter handles operations on the database as the table name of the database.
Popular Point says:
D is to instantiate a model based on the model file.
M is to instantiate a model object dynamically by directly instantiating the model method (thinkphp base class), even if the corresponding model file does not exist.
In a more popular sense:
The M instantiation parameter is the table name of the database.
D instantiation is the model file that you created under the Models folder yourself.
D is when you do not define a model, the system automatically defines a model for you, so that you do a simple data input or output.
Each action file should correspond to the model file, if you define model,
For example: $Form = D ("user") can be changed to $form = new Usermodel () (user refers to your model file name). (http://www.zzblo.com/study/php/418.html)