背景:我如今用的是Thinkphp3.1版本php
将须要的第三方类库文件放到:ThinkPHP\Extend\Library\ORG的路径下能够,this
我把类文件test.class.php放在ORG下的Net文件夹下(也能够本身新建一个文件夹)。spa
ThinkPHP\Extend\Library\ORG\Net\test.class.phpcode
类文件的名字要按照xxx.class.php的格式命名。对象
test.class.phpget
<?php class Test{ public $text=null; function __construct($param){ $this->text =$param; } public function get(){ return $this->text; } }
2.在控制器里引入该类文件文件,并使用它的成员属性和成员方法:it
class AdminAction extends Action { public function test(){ import('ORG.Net.Test'); //引入ORG文件夹下的Net文件夹下的Test.class.php文件 $test =new Test("hello,world"); //实例化对象 echo $test->get(); //调用方法 echo $test->text; //调用成员变量 } }
thinkPHP3.2 引入第三方类库的方法:io
第一种方法:function
1. 将第三方类库放在下class
命名规则:xxx.class.php,如:AliMgs.class.php
第三方类文件中头部要加命名空间:
2.在controller中实例化第三方类:
另外,也能够不把第三方类放在Ulit下,能够放在Org/Net下,或者本身新建一个两层文件夹,如:My/Lib
也能够本身新建一个文件夹,如: Library/BBB,在第三方类中,namespace以下:
在controller中使用以下:
另外,这种方法不能直接放在Library下。亲测。
第二种方法:
不须要使用命名空间。
在controller中调用改类库则要用import引入,类名前要加 \:
另外:
这种方法能够能够直接放在Library下,在controller中是以下调用:
注意:import中AliMgs前面有个点,少了就抛异常。
也能够本身新建一个文件夹,如:Library/BBB,在controller以下使用: