如果路径与文件夹结构不匹配,Symfony2 类加载器不起作用?
这是我当前的结构
plugins/
|---init.php
|---/plugin1/lib/
|---/plugin2/lib/
|---/Symfony/
我的代码如下:
set_include_path(DIR_FS_CATALOG.'plugins');
require_once(DIR_FS_CATALOG.'plugins/Symfony/Component/ClassLoader/UniversalClassLoader.php');
// load the class loader and dependency injection component
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespaces(array('plugins\\plugin1' => __DIR__.'/plugins/plugin1/lib', 'plugins' => DIR_FS_CATALOG.'plugins'));
$loader->registerNamespace('Symfony',__DIR__.'/plugins');
$loader->register();
use plugins\plugin1\MyClass;
MyClass::init();
致命错误:找不到类“plugins\plugin1\MyClass”
我想知道我做错了什么?任何帮助将不胜感激。
Here is my current structure
plugins/
|---init.php
|---/plugin1/lib/
|---/plugin2/lib/
|---/Symfony/
I have my code like this:
set_include_path(DIR_FS_CATALOG.'plugins');
require_once(DIR_FS_CATALOG.'plugins/Symfony/Component/ClassLoader/UniversalClassLoader.php');
// load the class loader and dependency injection component
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespaces(array('plugins\\plugin1' => __DIR__.'/plugins/plugin1/lib', 'plugins' => DIR_FS_CATALOG.'plugins'));
$loader->registerNamespace('Symfony',__DIR__.'/plugins');
$loader->register();
use plugins\plugin1\MyClass;
MyClass::init();
Fatal error: Class 'plugins\plugin1\MyClass' not found
I wonder what did I do wrong? Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Symfony2 类加载器符合 PSR-0 标准(https ://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)这意味着您的命名空间必须反映您的文件系统结构。
The Symfony2 class loader is PSR-0 compliant (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) which means, that your namespaces must reflect your file system structure.