我有一个使用命名空间的第三方库,我想将其添加到供应商目录中。由于某些原因,我无法为此库使用作曲家。使用 ClassLoader 的 add 方法添加它对我不起作用(“找不到类”)。详细地:
我正在使用 Symfony 2.1.7。
// app/autoload.php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add('Example', realpath(__DIR__.'/../vendor/example/src'));
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
供应商目录中的目录结构:
//vendor/example/src/Foo.php
namespace Example;
class Foo {
}
在我的控制器中使用它:
$bar = new \Example\Foo();
Result:
未找到类“Example\Foo”
我的错误在哪里?和/或:在 Symfony 2.1 中调试此问题的最佳方法是什么?
目录结构错误。 UniversalClassLoader(在 Symfony
这对我有用:
Directory structure
// 在 autoload.php 中
// Symfony 2.1 using Composer's ClassLoader
$loader->add('Example', realpath(__DIR__.'/../vendor/example/example/src'));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)