本文介绍了Symfony2中的getEntityManager()和getDoctrine()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这两个语句之间是否有任何区别:
$ this-> getDoctrine()-> getEntityManager() -> getRepository();
$ this-> getDoctrine()-> getRepository();
差异是否与我错过的任何OOP概念有关?
解决方案
一般而言,没有区别,因为
$ this-> getDoctrine()-> getRepository();
只是
<$ p $的助手p>
$ this-> getDoctrine()-> getEntityManager()-> getRepository();
您可以有多个实体管理器,然后从一个实体管理器中获取存储库会略有不同:
$ this-> getDoctrine()-> getRepository($ entityName,$ enityManagerName);
$ this-> getDoctrine()-> getEntityManager($ entityManagerName)-> getRepository($ entityName);
但同样,您得到的结果也没有差异。
在所有其他条件都相同的情况下,我会选择最短的东西。
Is there any difference between these two statements:
$this->getDoctrine()->getEntityManager()->getRepository();
$this->getDoctrine()->getRepository();
Does the difference relate to any OOP concept I am missing out?
解决方案
In general, no difference, since
$this->getDoctrine()->getRepository();
is just a helper for
$this->getDoctrine()->getEntityManager()->getRepository();
You can have several entity managers, and then there will be a slight difference in getting a repository from one:
$this->getDoctrine()->getRepository($entityName, $enityManagerName);
$this->getDoctrine()->getEntityManager($entityManagerName)->getRepository($entityName);
But again, no difference in the result you'll get.
All other things being equal, I'd go with the shortest one.
这篇关于Symfony2中的getEntityManager()和getDoctrine()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!