【问题标题】:Symfony 2: Add another namespace to Entity namespacesSymfony 2:向实体命名空间添加另一个命名空间
【发布时间】:2011-12-19 17:11:42
【问题描述】:

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

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: ~

提前致谢

【问题讨论】:

  • 你的问题解决了吗?

标签: symfony doctrine-orm


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    不完全确定将实体“分开”是什么意思,但如果您尝试将一个实体映射到同一数据库中的两个不同表,我认为这是不可能的,因为它被列为学说限制,请参阅: here.

    【讨论】:

    • 不,这不是我的意思,我的意思是我想创建我的实体文件,依赖于它们连接到的数据库,在我的 config.yml 中我想有orm: entity_managers: default: connection: default mappings: AcmeStoreBundle: ~ Foo: connection: Foo mappings: AcmeAnotherBundle: ~
    【解决方案3】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 2013-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-05
      • 1970-01-01
      相关资源
      最近更新 更多