tp3.2 the introduction of third party

, Introduce a third party library file .class.php
1.1 write namespace namespace library
1. namespace of Org \ Util;
2. the Auth {class
3.}
Save to ThinkPHP / Library / Org / Util / Auth.class.php. (That is to Think, Org namespace root class can be automatically loaded :)
In other Controller, examples of:
1. new new \ of Org \ Util \ the Auth ();
1.2 to manually load third party libraries
To load third-party libraries, including naming conventions and does not comply with the suffix library, and there is no way to use a namespace name or path library and space inconsistent, or if you just want to manually load the library file, we can be imported manually loading .
We can use the import method to import any class libraries, usage such as:

// Import Org library packages Library / Org / Util / Date.class.php library
Import ( "Org.Util.Date");
// import module below Home Application / Home / Util / UserUtil.class.php class library
import ( "Home.Util.UserUtil");
// module into the current library following
import ( "@ Util.Array.");
// import library packages Vendor library / Vendor / Zend / Server.class.php
import ( 'Vendor.Zend.Server');

For the import method, the system will automatically identify the location of the import library file, ThinkPHP can automatically identify the library package includes Think, Org, Com, Behavior and Vendor packages, and Library directory subdirectories, if you create a directory under Library a Test subdirectory, and create a UserTest.class.php library, so you can import:
import ( 'Test.UserTest');
Note, if your library does not use a namespace definition, instantiation need to add root namespace, for example:

public function index () {

import('Test.UserTest');
$test = new \UserTest();

}


3, ordinary .php extension manually load third-party native file
if your third-party libraries are placed in the Vendor list below, and all end with the .php file extension type, the use of namespaces is useless, then you can use the built-in system Vendor simplified introduction of the function. For example, we Zend \ Filter \ Dir.php put Vendor directory, this time path Dir file is Vendor \ Zend \ Filter \ Dir.php, we use the vendor only need to use the import method:

public function index(){

Vendor ( 'Zend.Filter.Dir');

$ Obj = new \ You ();

}

Moreover: If your file is abphp (b not class), then this may be introduced:
Vendor ( 'directory .a # b');
instance when objects to class ab {...} Example: new \ ab ( );
4, .php to manually load and process-oriented document
what process-oriented, there is no file class aaa {}, no operation example, be used directly.
We can use the native syntax:
use the method in the
controller: include_once '. / ThinkPHP / Library / Vendor / lib / aaa. bbb. php ';
thus perfectly introduces some of the primary process-oriented. php file.

import('Vendor.Wxpay.WxPayApi');
$test = new \WxPayApi();
$test->aa();

Guess you like

Origin www.cnblogs.com/JdsyJ/p/10991578.html