Home > PHP Framework > ThinkPHP > How to load external methods in thinkphp

How to load external methods in thinkphp

藏色散人
Release: 2022-12-07 09:11:59
Original
1295 people have browsed it

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");
Copy after login

② Import the class under the Home module

import("Home.Util.UserUtil");
Copy after login

③ Import the current Classes under the module

import("@.Util.Array");
Copy after login

④Import the vendor class library package

import('Vendor.Zend.Server');
Copy after login

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');
Copy after login

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!

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