Symfony 2:在实体命名空间中添加另一个命名空间



在我的symfony2应用程序中,我有两个数据库连接,我想保持实体类分开,因此在一个bundle中有一组实体类,在另一个bundle中有另一组实体类。然而,当尝试调用我的bundle时,由于某种原因没有注册为实体命名空间,错误如下:

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

我已经寻找了它设置实体名称空间的地方,我发现它在缓存文件

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

如何添加到数组?

新编辑:

我的配置。Yml如下,它应该有助于澄清问题:

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

Thanks in advance

我在尝试使用生成的CRUD表单时遇到了这个确切的问题。最终解决问题的方法是将首选实体管理器的名称作为参数添加到getEntityManager(),如下所示:

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

不完全确定你的意思是保持你的实体"分开",但如果你试图映射一个实体到两个不同的表在同一数据库中,我不认为这是可能的,因为它列为一个学说限制见:在这里。

关于使用多个实体管理器:

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

http://symfony.com/doc/master/reference/configuration/doctrine.html的映射配置

看一下prefix参数:

...
orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                OneBundle:
                    prefix: OneBundleEntityNamespace
        other:
            connection: other # check this :p
            mappings:
                OtherBundle:
                    prefix: OtherBundleEntityNamespace

最新更新