【问题标题】:Doctrine 2 Yaml Driver Not Even ATTEMPTING to Load ClassesDoctrine 2 Yaml 驱动程序甚至没有尝试加载类
【发布时间】:2011-04-08 08:39:17
【问题描述】:

我试图在 Doctrine 2.0 中从 Yaml 加载我的模式类,但我遇到了困难。可悲的是,Doctrine 2.0 文档是 ATROCIOUS。我认为 Doctrine 1.2 文档是废话...... 2.0 简直无法言喻。哇。无论如何,这是我目前所拥有的:

require_once(\config\paths\CLASS_LOADER);
$loader = new \Doctrine\Common\ClassLoader('Doctrine', \config\paths\PHP_LIBRARIES);
$loader->register();
$cache = new \Doctrine\Common\Cache\ArrayCache();

$config = new \Doctrine\ORM\Configuration;
$config->setMetadataCacheImpl($cache);
$driver = new \Doctrine\ORM\Mapping\Driver\YamlDriver(\config\paths\MODELS);
$config->setMetadataDriverImpl($driver);
$config->setQueryCacheImpl($cache);
$config->setProxyDir(\config\paths\PROXIES);
$config->setProxyNamespace('lib\orm\proxies');

$config->setAutoGenerateProxyClasses(true);//@PRODUCTION - set this false

$connectionOptions = array(
    'driver' => \config\db\DRIVER,
    'user' => \config\db\LOGIN,
    'password' => \config\db\PASSWORD,
    'dbname' => \config\db\TABLE,
    'host' => \config\db\HOST
);
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);

所有路径都是正确的。传递给 $connectionOptions 数组的所有常量都是正确的。模型路径是一个文件夹,其中包含诸如 ClaimStatus.dcm.yml 之类的文件,其中包含以下内容:

orm\ClaimStatus:
    type: entity
    table: claim_status
    id:
            id:
                    type: integer
                    generator:
                            strategy: identity
    fields:
            name:
                    type: string
            code:
                    type: string

然而,毕竟,实体管理器已经准备好了,我要做:

$em->find('orm\\Category',1);

但我得到的只是:

Warning: class_parents() [function.class-parents]: Class orm\Category does not exist and could not be loaded in /usr/share/php/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222
Fatal error: Uncaught exception 'ReflectionException' with message 'Class orm\Category does not exist' in /usr/share/php/Doctrine/ORM/Mapping/ClassMetadata.php on line 67

【问题讨论】:

    标签: php postgresql orm doctrine-orm


    【解决方案1】:

    YAML 驱动程序只获取 YAML 文件的路径,而不是 PHP 类文件本身。

    您将需要设置一个单独的自动加载器,它可以找到您的 PHP 类文件或手动包含它们。您可能可以使用 Doctrine 自动加载器:

    $loader = new \Doctrine\Common\ClassLoader('orm', 'path/to/orm/classes');
    $loader->register();
    

    【讨论】:

    • 好的。这绝对是我最初问题的“答案”,但现在出现了一个新问题。我做了一些命名空间重命名以使其与自动加载器配合得很好,但无论如何这里是问题:致命错误:未捕获的异常'Doctrine\ORM\Mapping\MappingException' 带有消息'Property'parent' in "lib\orm\classes \Category" 已经被声明了,但它只能在 /usr/share/php/Doctrine/ORM/Mapping/MappingException.php 的第 156 行声明一次 我真的不明白这是怎么可能的。它显然只声明过一次。
    • 没关系。我智障...... YAML 中有一个错字。一切都很好。
    • 是否可以自动执行此操作?或者我真的必须为我的所有实体命名空间包含上述两行吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多