在我的 Symfony 3.0 项目中,我有一个名为 ImageGroups
的实体和一个使用 ImageGroups
实体的 ImageGroupsRepository
存储库。我还制作了一个带有 ImagesRepository
Images
实体
在 ImageGroupsRepository
中,我有一个名为 getUserImageGroups
的方法,在 ImagesRepository
中,我有一个名为 add
的方法。
我想问的是如何使用ImageGroupsRepository
的getUserImageGroups
方法到ImagesRepository
的add
?
最佳答案
A.L 给出的答案是正确的,我只是想提供一种替代方法来访问实体管理器,而无需再次调用该函数,通过 $this->_em
:
class ImagesRepository extends EntityRepository
{
public function add()
{
$imagesGroups = $this->_em
->getRepository('AcmeBundle:ImageGroups')
->getUserImageGroups();
// …
}
}
如果您查看 documentation for EntityRepository您会看到 getEntityManager()
函数只返回 EntityRepository
类的 protected $_em
成员。
关于php - 交响乐 3.0 : Reuse entity in repository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35683369/