In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use thinkphp d method". In daily operation, I believe many people have doubts about how to use thinkphp d method. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use thinkphp d method" Next, please follow the editor to study!
The thinkphp d method is used to instantiate a custom model class, which is an encapsulation of Model class instantiation by the ThinkPHP framework. Its syntax is "D ('[project: / /] [grouping /] model', 'model layer name')", and its return value is the instantiated model object.
Operating environment of this article: Windows7 system, thinkphp v5.1, DELL G3 computer
How to use the thinkphp d method?
Detailed explanation of ThinkPHP function: d method
D method
D method should be used to instantiate custom model class, which is an encapsulation of Model class instantiation by ThinkPHP framework, and implements singleton pattern, which supports cross-project and group calls. The call format is as follows:
D ('[project: / /] [grouping /] model', 'model layer name')
The return value of the method is the instanced model object.
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 Model base class is instantiated, and the instantiated model is not repeatedly de-instantiated.
The most common use of the D method is to instantiate a custom model for the current project, such as:
/ / instantiate the User model $User = D ('User')
The Lib/Model/UserModel.class.php file under the current project is imported, and then the UserModel class is instantiated, so the actual code may be equivalent to the following:
Import ('@ .Model.UserModel'); $User = new UserModel ()
But if you use the D method, if the UserModel class does not exist, it will be called automatically
New Model ('User')
And the second call does not need to be instantiated again, which can reduce a certain amount of object instantiation overhead.
The D method can support model instantiation across groups and projects, such as:
/ / instantiate User model D ('Admin://User') of Admin project / / instantiate User model D (' Admin/User') of Admin grouping
Note: to implement the cross-project invocation model, you must ensure that the directory structure of the two projects is juxtaposed.
Since version 3.1, due to the addition of support for hierarchical models, the D method can also instantiate other models, such as:
/ / instantiate UserService class $User = D ('User','Service'); / / instantiate UserLogic class $User = D (' User','Logic'); D ('User','Service')
Lib/Service/UserService.class.php is imported and instantiated, which is equivalent to the following code:
Import ('@ .Service.UserService'); $User = new UserSerivce (); at this point, the study on "how to use the thinkphp d method" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.