2014-10-10 111 views
1

我尝试在Symfony 2.5中使用Doctrine并将XML配置用于实体映射。Doctrine2 + Symfony2:如何使用Symfony2命名空间的学说实体?

我有一个命名空间中的类BarACME\TestBundle\Entity\Foo\Bar

正如我有他们不可能都驻留在ACME\TestBundle\Entity命名空间中许多实体,但必须付诸子命名空间。

创建实体没有问题,但我无法弄清楚在哪里放置ORM XML配置文件。

我试过Resources/config/doctrine/Foo/Bar.orm.xml,不找到映射文件:

$ php app/console doctrine:schema:create --dump-sql 
No Metadata Classes to process. 

我试过Resources/config/doctrine/Bar.orm.xml,而忽略了另外Foo命名空间的Unter Entity,虽然完整的命名空间中Bar.orm.xmlname元素给出正确。

$ php app/console doctrine:schema:create --dump-sql     
[Doctrine\Common\Persistence\Mapping\MappingException] 
Class 'ACME\TestBundle\Entity\Bar' does not exist 

我在想什么? XML映射文件驻留在这些名称空间类中的正确位置是什么?

在此先感谢您的帮助。

+1

尝试使用'Foo.Bar.orm.xml'。 – 2014-10-10 11:22:39

+0

@ user3749178是正确的。文件映射文件位于Resources/config/doctrine下。这是一种双向映射。即使映射文件包含实体的全名,系统也需要能够根据实体名称找到映射文件。不知道这是记录在哪里。我前段时间通过查看错误消息发现了它。也可以使用不同的映射目录,但这很痛苦。 http://symfony.com/doc/current/reference/configuration/doctrine.html#mapping-configuration – Cerad 2014-10-10 13:22:54

回答

1

使用@ user3749178 Foo.Bar.orm.xml的建议工作,并且是解决问题的最简单方法,尽管所有映射文件都在一个目录中。

也有可能基于具有的一切个人目录:

http://symfony.com/doc/current/reference/configuration/doctrine.html#mapping-configuration

下面是一个例子配置:

doctrine: 

    orm: 
    default_entity_manager:  default 
    auto_generate_proxy_classes: %kernel.debug% 

    entity_managers: 

    default: 
     connection: default 
     mappings: 
     foo1: 
      prefix: Cerad\Bundle\ProjectGameBundle\Doctrine\Entity\Foo1 
      type: yml 
      dir: src/ProjectGameBundle/Doctrine/EntityMapping/Foo1 
      is_bundle: false 
     foo2: 
      prefix: Cerad\Bundle\ProjectGameBundle\Doctrine\Entity\Foo2 
      type: yml 
      dir: src/ProjectGameBundle/Doctrine/EntityMapping/Foo2 
      is_bundle: false 

你基本上为包含实体每个目录一一对应。