Home > PHP Framework > ThinkPHP > body text

What is the usage of vendor in thinkphp3.2

WBOY
Release: 2022-04-25 11:16:55
Original
4777 people have browsed it

In thinkphp3.2, vendor is used to import third-party class libraries. The default import path of this method is the Vendor directory of the thinkphp system directory. The default suffix is ​​".php" and the syntax is "vendor(to import class library, imported base path, imported class library suffix)".

What is the usage of vendor in thinkphp3.2

The operating environment of this article: Windows 10 system, ThinkPHP version 3.2, Dell G3 computer.

What is the usage of vendor in thinkphp3.2

Vendor method imports third-party class library

Third-party class library

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

The ThinkPHP convention for the class library imported earlier using automatic loading or the import method is to use .class.php as the suffix. Non-such suffixes need to be controlled through the parameters of import.

But for the third category library, since there is no such agreement, its suffix can only be considered to be php. In order to easily introduce class libraries from other frameworks and systems, ThinkPHP specifically provides the function of importing third-party class libraries. Third-party class libraries are uniformly placed under the ThinkPHP system directory/Vendor and imported using the vendor method.

vendor method

Syntax:

boolen vendor(class, baseUrl, ext)
Copy after login

class Required, indicating the class library to be imported, using the namespace method.

baseUrl Optional, indicating the base path of import. If omitted, the system uses the ThinkPHP system directory/Vendor directory.

ext Optional, indicating the imported class library suffix, the default is .php.

The difference from 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.

The example is as follows:

Used in the function function:

Vendor('Phpqrcode.phpqrcode');
Copy after login
/**
 * 生成二维码
 * @param  string  $url  url连接
 * @param  integer $size 尺寸 纯数字
 */
function qrcode($url,$size=4){
    Vendor('Phpqrcode.phpqrcode');
    if (strpos($url, 'http')===false) {
        $url='http://'.$url;
    }
    QRcode::png($url,false,QR_ECLEVEL_L,$size,2,false,0xFFFFFF,0x000000);
}
Copy after login

Recommended learning: "PHP Video Tutorial

The above is the detailed content of What is the usage of vendor in thinkphp3.2. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!