Home > Article > PHP Framework > How 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');".
#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!