Symfony的2:另一个命名空间添加到实体的命名空间
问题描述:
在我的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: ~
在此先感谢
答
我试图使用生成的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#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
你解决了你的问题? – 2012-06-17 00:16:27