2014-10-10 117 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 

你基本上爲包含實體每個目錄一一對應。