search
HomePHP FrameworkThinkPHPHow to load external methods in thinkphp

thinkphp loads external methods: 1. Import the class library through the import method, and its import syntax is such as "import("Org.Util.Date");"; 2. Use vendor to import external classes, and its import syntax is as follows "Vendor('Zend.Filter.Dir');".

How to load external methods in thinkphp

#The operating environment of this tutorial: Windows 7 system, thinkphp version 3.2, Dell G3 computer.

How to load external methods in thinkphp?

Thinkphp's method of importing external classes

I believe many people are troubled by various unsuccessful attempts to use external classes when using TP

Below Let me introduce the reference method and pay attention to the details in detail

Manually load the third-party class library

Since the third-party class library does not have a specific namespace, you need to use the following methods to manually import it

1. The import method can import any class library

① Import the org class library package

import("Org.Util.Date");

② Import the class under the Home module

import("Home.Util.UserUtil");

③ Import the current Classes under the module

import("@.Util.Array");

④Import the vendor class library package

import('Vendor.Zend.Server');

Pay attention to the correctness of the path. After successfully introducing these classes, be sure to instantiate these classes before calling them.

2. Use vendor to import external classes

Note: There is a case difference under Unix or Linux hosts, so when using the import method, pay attention to the case of the directory name and class library name. , otherwise the import will fail.

Vendor('Zend.Filter.Dir');

Participate in the official manual for details: http://document.thinkphp.cn/manual_3_2.html#autoload;

Recommended learning: "thinkPHP Video Tutorial"

The above is the detailed content of How to load external methods in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools