2011-12-19 116 views
5

在我的Symfony2应用程序中,我有两个数据库连接,我想保持实体类独立的,因此在一个包一组实体类和另一束另一组。然而试图打电话给我包的时候,它没有注册为实体命名空间某些原因,错误如下:Symfony的2:另一个命名空间添加到实体的命名空间

Unknown Entity namespace alias 'AcmeStaffBundle'. 
500 Internal Server Error - ORMException 

我已经看过了它设置实体的命名空间,而且我也发现在缓存文件中

$e = new \Doctrine\ORM\Configuration(); 
$e->setEntityNamespaces(array('AcmeStoreBundle' => 'Acme\\StoreBundle\\Entity')); 

我该如何将此添加到数组?

新的编辑:

我config.yml如下:这应该有助于澄清问题:

orm: 
    entity_managers: 
     default: 
      connection:  default 
      mappings: 
       AcmeStoreBundle: ~ 
     Foo: 
      connection:  Foo 
      mappings: 
       AcmeFooBundle: ~ 

在此先感谢

+0

你解决了你的问题? – 2012-06-17 00:16:27

回答

0

不完全知道你的意思是保持你的什么实体“分开”,但如果你试图将一个实体映射到同一个数据库中的两个不同的表,我认为这不可能,因为它列为一个学说的限制见:here

+3

都能跟得上这个心不是我的意思,我的意思是,我要创建我的实体文件单独依赖他们连接到数据库上,在我config.yml我想有 'ORM: entity_managers: 默认: 连接:默认 映射: AcmeStoreBundle:〜 富: 连接:富 映射: AcmeAnotherBundle:〜' – Matt 2011-12-20 16:02:16

1

我试图使用生成的CRUD表单时遇到了这个确切的问题。什么问题终于解决了被添加首选实体管理器作为参数的名称getEntityManager()这样的:

$em = $this->getDoctrine()->getEntityManager('Foo'); 
0

使用多个实体管理器:

http://symfony.com/doc/master/cookbook/doctrine/multiple_entity_managers.html

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

取看看到prefix参数:

... 

orm: 
    auto_generate_proxy_classes: %kernel.debug% 
    default_entity_manager: default 
    entity_managers: 
     default: 
      connection: default 
      mappings: 
       OneBundle: 
        prefix: One\Bundle\Entity\Namespace 
     other: 
      connection: other # check this :p 
      mappings: 
       OtherBundle: 
        prefix: Other\Bundle\Entity\Namespace