The specific difference between m method and D method in thinkphp
Source: Internet
Author: User
M and D methods are used to instantiate a model class, the M method is used to instantiate an underlying model class efficiently, and the D method is used to instantiate a user-defined model class (thinkphp). Use M method if this is the case, consider using the M method: To perform a simple curd operation on a datasheet without complex business logic when only a single table has more complex business logic, the M method is combined with the instantiated Commonmodel class to use the M method and even You can simply look at the operation of the datasheet that corresponds to the parameter table name: $User = M (' User '); use 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 validation function (CR The Eate () method is implemented), business logic, such as association models, is complex and involves many tables that define business logic within a custom model class (under the Lib/model directory) and want to implement these business logic in an operation the other D method does not support cross project calls, and needs to be used: $ user = D (' user ', ' Admin '); //The User model below the Admin project $User = D (' Admin.user '); //enabled the project grouping prompt after the project grouping is enabled, the Model class does not necessarily correspond to the project grouping. 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. The summary m and D methods can all be used directly without the existence of the model class file, but the M method is more efficient, but the D method must be used 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. above is a summary of the difference between M method and D method, M method and D sideThe law should be chosen according to the actual situation.
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