很久没有用过TP了,自定义扩展文件怎么加载的都不太清楚了,重新捋一遍,记录一下。
ThinkPHP版本 ^6.1.0
目录
1.将自定义扩展文件放入extend

2.设置类文件命名空间
extend下直接是类文件,不需设置命名空间
extend\Test.php
<?php
class Test
{
public function index()
{
echo '我是测试文件-没有层级';
}
}
有层级的类文件,则需设置命名空间
Extend/test/Test.php
<?php
namespace 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;
}

文章介绍了在ThinkPHP6.1.0版本中如何加载自定义扩展文件。无层级的类文件不需要设置命名空间,而在有层级的类文件中需指定相应的命名空间,如`namespacetest;`。最后通过示例代码展示了如何测试这些自定义类的效果。
580

被折叠的 条评论
为什么被折叠?



