本文介绍了将一个命名空间添加到已配置的EntityManager中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个EntityManager实例完全配置和工作。问题是如何向这个EM添加一个额外的命名空间? $ em-> getConfiguration() - > addEntityNamespace 'MyGreatBundle','My\GreatBundle\Entity');
这不工作,抛出如下:
解决方案
我设法解决了这个问题,不得不添加驱动程序:
$ namespace ='My\GreatBundle\Entity';
$ configuration = $ em-> getConfiguration();
$ annotationDriver = new AnnotationDriver(
$ this-> container-> get('annotation_reader'),
[__DIR__。'/../Entity']
) ;
/ ** @var MappingDriverChain $ driver * /
$ driver = $ configuration-> getMetadataDriverImpl();
$ driver-> addDriver($ annotationDriver,$ namespace);
$ configuration-> addEntityNamespace('MyGreatBundle',$ namespace);
I've got an EntityManager instance fully configured and working. The question is how to add an additional namespace to this EM?
$em->getConfiguration()->addEntityNamespace('MyGreatBundle', 'My\GreatBundle\Entity');
This does not work, throws the following:
解决方案
I managed to fix this issue, had to add the driver too:
$namespace = 'My\GreatBundle\Entity';
$configuration = $em->getConfiguration();
$annotationDriver = new AnnotationDriver(
$this->container->get('annotation_reader'),
[__DIR__ . '/../Entity']
);
/** @var MappingDriverChain $driver */
$driver = $configuration->getMetadataDriverImpl();
$driver->addDriver($annotationDriver, $namespace);
$configuration->addEntityNamespace('MyGreatBundle', $namespace);
这篇关于将一个命名空间添加到已配置的EntityManager中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!