【发布时间】:2012-08-04 12:17:50
【问题描述】:
目前我正在学习如何使用 Symfony2。我到了他们解释如何使用 Doctrine 的地步。
在给出的示例中,他们有时使用实体管理器:
$em = $this->getDoctrine()->getEntityManager();
$products = $em->getRepository('AcmeStoreBundle:Product')
->findAllOrderedByName();
在其他示例中不使用实体管理器:
$product = $this->getDoctrine()
->getRepository('AcmeStoreBundle:Product')
->find($id);
所以我实际上在没有获取实体管理器的情况下尝试了第一个示例:
$repository = $this->getDoctrine()
->getRepository('AcmeStoreBundle:Product');
$products = $repository->findAllOrderedByName();
得到了同样的结果。
那么我什么时候真正需要实体管理器,什么时候可以一次访问存储库?
【问题讨论】:
标签: symfony doctrine-orm entitymanager