Symfony2 中的 getEntityManager() 和 getDoctrine()

2024-04-25

这两种说法有什么区别吗:

$this->getDoctrine()->getEntityManager()->getRepository();

$this->getDoctrine()->getRepository();

这种差异是否与我遗漏的任何 OOP 概念有关?


一般来说,没有区别,因为

$this->getDoctrine()->getRepository();

只是一个帮助者

$this->getDoctrine()->getEntityManager()->getRepository();

您可以有多个实体管理器,然后从一个实体管理器获取存储库会略有不同:

$this->getDoctrine()->getRepository($entityName, $enityManagerName);
$this->getDoctrine()->getEntityManager($entityManagerName)->getRepository($entityName);

但同样,您得到的结果没有区别。

在其他条件相同的情况下,我会选择最短的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Symfony2 中的 getEntityManager() 和 getDoctrine() 的相关文章

随机推荐