很久没有用过TP了,自定义扩展文件怎么加载的都不太清楚了,重新捋一遍,记录一下。
ThinkPHP版本 ^6.1.0
目录
1.将自定义扩展文件放入extend
2.设置类文件命名空间
extend下直接是类文件,不需设置命名空间
extend\Test.php
<?phpclass Test{public function index(){echo '我是测试文件-没有层级';}}
有层级的类文件,则需设置命名空间
Extend/test/Test.php
<?phpnamespace test;class Test{public function index(){echo '我是测试文件-命名空间是{test}';}}
3.测试效果
public function index(){print_r((new \Test())->index());echo "<pre>";print_r((new \test\Test())->index());die;}