我现在正在测试将我的应用程序从SplAutoloading迁移到Symfonies autoloader。
我的应用程序结构是
> Components
> Models
> Core
Test.php
Index.php我的Test.php是这样的
namespace Core;
class Test {
}正在尝试将其加载到我的index.php中
define('__WEB_ROOT__', __DIR__);
//Symfony Class Loader
require_once __WEB_ROOT__ . '/Components/ClassLoader/UniversalClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$oLoader = new UniversalClassLoader();
$oLoader->registerNamespaces(
array(
'Core' => __WEB_ROOT__ . '/Models/Core/'
)
);
$oLoader->register();
use Core\Test;
$oTest = new Test();不知道为什么不能这样加载这个类吗?有什么帮助吗?这里的正确用法是什么?
发布于 2014-04-13 01:18:50
设置的文件路径不应包含命名空间名称。因此,如果Core\Test位于__WEB_ROOT__/Models/Core/Test.php中,则应将Core名称空间注册到__WEB_ROOT__/Models
$oLoader->registerNamespaces(array(
'Core' => __WEB_ROOT__ . '/Models/',
));https://stackoverflow.com/questions/23028739
复制相似问题