In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the difference between m method and d method in thinkphp". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The difference between m method and d method in thinkphp: 1, m method does not need to create model class file, but d method must create model class; 2, d method instantiates specific model class, m method instantiation does not need to load specific model class.
This article operating environment: Windows10 system, thinkphp v5.1, Dell G3 computer.
What is the difference between m method and d method in thinkphp
The D method can automatically detect the model class. If there is a custom model class, the custom model class is instantiated. If it does not exist, the\ Think\ Model base class of the system is instantiated, and the instantiated model is not repeatedly de-instantiated.
The D method usually instantiates a specific model class when it is used to instantiate a model class. If you are only doing basic CURD operations on the data table, then instantiating with the M method, the performance will be higher because you do not need to load the specific model class.
Both the M method and the D method in ThinkPHP are used to instantiate a model class, the M method is used to instantiate a base model class efficiently, and the D method is used to instantiate a user-defined model class.
Use the m method
Consider using the M method if:
When performing simple CURD operations on a data table without complex business logic, when only individual tables have more complex business logic, use the M method in conjunction with the instantiated CommonModel class
The M method can even simply look at the operation of the data table corresponding to the parameter table name:
$User = M ('User')
Use D method
Consider using the D method if:
Need to use some advanced functions in the ThinkPHP model, such as automatic verification function (implemented in the create () method), association model and other business logic is more complex, and many tables involved define the business logic in the custom model class (Lib/Model directory), but want to implement these business logic in the operation
In addition, method D does not support cross-project calls, so you need to use:
$User = D ('User',' Admin'); / instantiate the User model under the Admin project $User = D ('Admin.User'); / / Project grouping is enabled
Prompt
When project grouping is enabled, the Model class does not necessarily correspond to project grouping. The model classes shared by multiple project teams are placed in the Model directory and can be instantiated directly using D ('ModelName'). While D ('User.UserInfo') does not mean that User is necessarily a project grouping, it can simply be a catalog of files under Model. D (' User.UserInfo') instantiates UserInfo model classes under the User directory.
Summary
Both the M method and the D method can be used directly in the absence of the model class file, but obviously the M method is more efficient; but to use the business logic in the model class, the D method must be used.
A more vivid analogy is: M method is like a computer that has just installed an operating system, it can only use some basic functions, while D method is like installing some application software such as Office and QQ on the installed system, the function is more powerful, and the whole computer runs slower at the same time.
The above is some summary of the difference between M method and D method, M method and D method should be selected according to the actual situation.
This is the end of the content of "what is the difference between m method and d method in thinkphp". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.