thinkphp Development Framework function Detailed: D method

Source: Internet
Author: User
Keywords Development framework function D method thinkphp
Tags calls class cross custom development development framework framework function

D method

D method should be used more methods, used to instantiate the custom model class, is a thinkphp framework for the model class instantiation of a package, and implemented a singleton mode, support cross project and group calls, the call format is as follows:
D (' [Project://][Group/] model ', ' model layer name ')
The return value of the method is the instantiated model object.

The D method can automatically detect the model class and, if there is a custom model class, instantiate the custom model class and, if it does not, instantiate the model base class and not repeat the instantiated models.
The most common use of the D method is to instantiate a custom model for the current project, for example:

&http://www.aliyun.com/zixun/aggregation/37954.html ">NBSP; Instantiate the user model $User = D (' user ');

Imports the lib/model/usermodel.class.php file under the current project and then instantiates the Usermodel class, so the actual code might be equivalent to the following:

Import (' @. Model.usermodel '); $User = new Usermodel ();

However, if the D method is used, if the Usermodel class does not exist, it is automatically invoked

New Model (' User ');

And the second call does not need to be instantiated again to reduce the cost of a certain object instantiation.
The D method can support cross grouping and project instantiation models, for example:

Instantiate the user Model D (' admin://user ')//Of the admin project with the user Model D (' Admin/user ') of the admin group

Note: To implement a cross project invocation model, you must ensure that the directory structure of the two projects is tied.

Starting with version 3.1, the D method can also instantiate other models because of increased support for layered models, such as:

Instantiate the UserService class $User = d (' user ', ' service ');//Instantiate userlogic class $User = d (' user ', ' Logic ');D(' user ', ' service ');

is imported and instantiated, equivalent to the following code: lib/service/userservice.class.php

Import (' @. Service.userservice '); $User = new Userserivce ();
Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.