php - 交响乐 3.0 : Reuse entity in repository

标签 php symfony

在我的 Symfony 3.0 项目中,我有一个名为 ImageGroups 的实体和一个使用 ImageGroups 实体的 ImageGroupsRepository 存储库。我还制作了一个带有 ImagesRepository

Images 实体

ImageGroupsRepository 中,我有一个名为 getUserImageGroups 的方法,在 ImagesRepository 中,我有一个名为 add 的方法。

我想问的是如何使用ImageGroupsRepositorygetUserImageGroups方法到ImagesRepositoryadd

最佳答案

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/

相关文章:

php - 为什么在 composer 中更新依赖项这么慢?

php - 如何替换以 "[id"开头、中间部分未知并以 "]"结尾的字符串?

php - Yii CRUD 更新 - 错误 400 - 复合键导致问题

php - Symfony Doctrine,从带有连接的子查询中选择

php - Symfony 5 - 基于浏览器语言的网站翻译后重定向

php - Doctrine "group by"不返回所有现有对象

Php通过html表单选择行,并写入txt文件

php - 一个不工作的 mysql 删除查询。为什么?

php - 在表单上使用 php 和 POST,但 request_method 说它是 GET

php - Doctrine 映射一个不存在的类