The difference between ThinkPHP shortcut method D and M. Simply put, if the M method is used, the corresponding model class does not need to be defined (even if there is a definition, it will not be read ), generally, such a Model can only call some methods in the Model class of some basic system models. If you use the D method to instantiate a model, you must have a corresponding model class file. you can call some custom ThinkPHP shortcuts for the model. The difference between D and M
Simply put, the M method does not need to define the corresponding model class (even if there is a definition, it will not be read ), generally, such a Model can only call some methods in the Model class of some basic system models. If you use the D method to instantiate a model, you must have a corresponding model class file. you can call some custom methods or attributes of the model, in addition, D is also required for business logic such as automatic verification or functions in the file corresponding to the Mode.
For example, M is a newly installed operating system, and only the applications that come with the system do not have their own installed applications (so you can only call the properties and methods provided by the built-in Model) d. third-party applications that have already been installed are more widely used (you can call the attributes and methods defined by the model class), but obviously, after many third-party applications are installed, the system performance is reduced and the execution is slowed down, but the function is obviously powerful.
?
DMethodIt is used to quickly create an instance of a model object and is single-sample, for example:
$ User = D ("User ");
Equivalent
$ User = new UserModel ();
?
The m instantiation parameter is the database table name.
D. instantiate the model file created in the model folder.
?
The main differences between D and M are:
The M method does not need to create a model 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 ing object for a data table.
First: $ Test = D ('test ')
Type 2: $ Test = new Model ('test ')
Although the two methods can perform select, insert, delete, and udpate operations on data, there is a big difference in data verification. in the first way, the data check function is provided when a model is instance, if the title is not entered, the system prompts "enter the title" (this is an automatic verification feature provided by tp, and the verification criteria must be defined in the corresponding model );
The D method can automatically detect the model class. if it does not exist, an exception is thrown. At the same time, the instantiated model will not be repeatedly instantiated (single instance ).
The default D method can only call models under the current project (or application ).
?
Example: $ user = new UserModel ();
Equivalent to $ user = D ('user ');
?
If an empty model is instantiated
For example, $ Demo = new Model ();
It is equivalent to $ Demo = M ();