1

我在将 Classloader 添加到 Doctrine 2 项目时遇到了一些问题。我有这样的简单目录结构:

  • 配置(引导文件)
  • html(带有模板/图像/js等的docroot)
  • php
  • 实体(学说 2 实体)
  • 响应(一些传输对象)
  • 服务(处理 api 和业务逻辑 - 像 java 中的会话 bean)

每个 php 子目录都属于自己的命名空间(与目录名称相同)。
我想使用前面提到的类加载器来加载这三个不同的包,所以我的引导程序看起来像这样:

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', $lib );
$classLoader->register();

$responsesCL = new \Doctrine\Common\ClassLoader('Responses', __DIR__.'/../php');
$responsesCL->register();

$entitiesCL = new \Doctrine\Common\ClassLoader('Entities', __DIR__.'/../php');
$entitiesCL->register();

$servicesCL = new \Doctrine\Common\ClassLoader('Services', __DIR__.'/../php');
$servicesCL->register();

粗体 DIR 实际上是__ DIR __php 常量。

现在,我在我的服务包中指的是实体,这就是问题开始的地方,由于某种原因,由于找不到文件问题,我得到了错误,例如:

无法打开所需的“/var/www/projects/PlatformManagement/config/../php/Services/Entities/User.php”(include_path='.:/usr/share/pear:/usr/share/php') /usr/share/pear/Doctrine/Common/ClassLoader.php 在第148行

不知何故,路径中有额外的“服务”,显然它不是有效的路径。我有点纳闷,为什么会有那个额外的目录?我三次检查了所有命名空间、调用,它们都正常。

我需要另一双眼睛才能看到,我假设我在这里遗漏了一些明显的东西,但无法发现它:|

哦,如果有帮助的话,这是 Fedora 上最新的 Doctrine 2 Beta (4) 和 php 5.3.3。

谢谢,格雷格

4

1 回答 1

0

有没有类似 Doctrine\ORM\Tools\Setup::registerAutoloadPEAR() 的东西?

Doctrine 的 Autoloader 可能会产生意想不到的行为,因为它加载基于 PHP 包含路径的类。

参考这个

在你的情况下,实体应该有

namespace Entities;

声明,没有别的。

并使用如下实体,

use Entities\User;
new User;
于 2013-02-24T00:07:33.243 回答