tp5 类库映射需要怎么操作?

浏览:1967 发布日期:2017/09/15 分类:ThinkPHP5专区 关键字: tp5 类库映射 怎么定义定义
比如说我在thinkphp/library目录下新建一个test的文件夹,底下放Test.php,
Test.php代码如下:namespace test;
class Test 
{
    public function hello(){
        return "hello";
    }
然后我在public/index.php的最后使用:\think\Loader::addNamespace('test',LIB_PATH.'test/');
\think\Loader::addClassMap('test\Test',LIB_PATH.'test\Test.php');
之后在index模块下的TestIndex控制器下,测试,代码如下:namespace app\index\controller;

use think\Controller;
use test\Test;

class TestIndex extends Controller
{
    public function phello(){
        $obj = new Test();
        return $obj->hello();
    }
}
但浏览器仍然报错: Class 'test\Test' not found

请问我该怎么定义类库映射呢?


最佳答案
评论( 相关
后面还有条评论,点击查看>>