The ThinkPHPvendor method imports third-party class libraries.

Source: Internet
Author: User
A third-party class library is a class library other than the ThinkPHP framework and application project class library. it is generally provided by a third-party system or product, such as a third-party class library for systems such as Smarty and Zend.

Third-party class libraries refer to other class libraries except the ThinkPHP framework and application project class libraries, which are generally provided by third-party systems or products, such as Smarty and Zend.
System class libraries.

Previously, the class library imported using the automatic loading or import method was defined as. class. php.
If it is not such a suffix, it must be controlled by the import parameter.

But for the third class library, since there is no such convention, its suffix can only be considered as php
. To facilitate the introduction of other frameworks and system class libraries, ThinkPHP specifically provides the function of importing third-party class libraries. Third-party class libraries are stored in the ThinkPHP system directory/Vendor
And use the vendor method to import.
Vendor method

Use of the vendor method and import
The method is completely consistent, but its default value is slightly different.

Syntax:

Boolen vendor (class, baseUrl,
Ext)

Parameter description: parameter description
The class is required. it indicates the class library to be imported. it adopts the namespace method.
BaseUrl
Optional. it indicates the basic path for import. If this parameter is omitted, the system uses the ThinkPHP system directory/The Vendor Directory.
Ext (optional) indicates the suffix of the imported class library. the default value is. php.
.

The difference with the import method is that the default import path of the vendor method is the ThinkPHP system directory/Vendor Directory, and the default suffix is. php.
.
An example of how to import a third-party class library using the vendor method

For example, if we want to introduce the Zend FilterDir. php file, we will put the file with a directory in the Vendor
Directory. at this time, the path of the Dir file is VendorZendFilterDir. php. Use vendor
Method import:

Vendor ('zend. Filter. dir ');

For files that contain the. symbol, replace the. symbol with the # symbol or specify
Ext parameter.
Prompt

In fact, the vendor method calls the import method to implement class library import, and the vendor method also supports custom import paths. However
ThinkPHP stipulates that the class library files of all third-party frameworks should be put under the vender Directory of the system. Therefore, we should try our best to abide by this Convention.

In addition, please pay special attention to the vendor
The first letter must be in lower case (the official manual is in upper case ).

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.