thinkphp Development Framework function Detailed: Import method

Source: Internet
Author: User
Keywords Development framework function import method thinkphp
Tags alias array class development development framework directory example framework

The import method is an encapsulation implementation of the thinkphp framework for Class library imports, especially for import support for Project class libraries, extended class libraries, and Third-party class libraries, and earlier versions of the Import method can import directories and wildcard imports like Java import methods, and then consider performance issues. Improved and simplified in subsequent release updates, so the usage is straightforward. Call Format:
Import (' Class library name ', ' Start path ', ' Class library suffix ')
The Imprt method has an alias noun method that is specifically used to import a Third-party class library, except that the start path and class library suffix defaults are different.
Let's analyze the specific usage:

Import System base Class Library

The system base Class library actually refers to the Think Class library package, where the directory refers to the core Lib directory of the framework, and the import method can be used to import system base class libraries, for example:

Import (' Think.Util.Array ');

Represents the Lib/util/array.class.php class library file under the Import system directory, which is equivalent to the way we use

Require&http://www.aliyun.com/zixun/aggregation/37954.html ">NBSP; Think_path ' lib/util/array.class.php ';

Multilevel catalogs can be supported, for example:

Import (' Think.Util.U1.ClassA '); Import (' Think.Util.U1.A2.ClassB ');

After you import the class library through the import method, you can instantiate the class library.

Import an extended class library

The Extended class library is located under the Extend/library directory, which is the system's public extended class library directory, and currently supports only Org and COM packages for the Extended class library package.

Import (' ORG. Util.image '); Import (' Com.Sina.OAuth ');

Will import the third party class libraries (extend/library/org/util/image.class.php and extend/library/com/sina/oauth.class.php class library files, respectively) below the extended directory. The third party Class library package can only support org and COM two, and the following subdirectories are optionally added.

Import Project Application Class Library

If you do not specify a start import path, the class library package think, ORG, COM is considered an import Project Application class library, for example:

Import ("MyApp.Action.UserAction"); Import ("MyApp.Model.InfoModel");

Represents the Useraction and Infomodel class library files that import MyApp projects, since we are typically importing the class libraries below the current project, so we can write a simple:

Import (@. Action.useraction "); Import ("@.model.infomodel");

The @ symbol indicates that the class library under the current project is imported, which in turn facilitates code porting of the Project class library, and does not need to be changed if the project name changes or moves below the other item.

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.