thinkphp5手动注册命名空间

手动注册 命名空间.利用application/config.php配置文件来注册命名空间
1:在application目录同级创建一个myExtend文件夹,里面再创建一个myTest文件夹.里面放一个myTest.php,里面写
<?php
namespace myTest;
class myTest{ 
public function sayHello(){
print('sayHello,myTest!');

}

2:打开config.php 找到 并加入自己的文件路径,
// 注册的根命名空间
'root_namespace' => [
'myTest' => '../myExtend/myTest/'
],
3:回到application\index\controller\Index.php,开头加入use myTest;
然后在function index()里面加入
$Test= new myTest\myTest();
$Test->sayHello();
4:浏览器打开 http://www.XXX.com/index/index/index
看到输出 sayHello,myTest!

posted @ 2018-07-04 12:53  码农骆驼  阅读(907)  评论(0编辑  收藏  举报