【发布时间】:2012-06-18 08:48:10
【问题描述】:
我在 Entity 类中有这个功能,但 getDoctrine 不喜欢...
public function getObject()
{
$em = $this->getDoctrine()->getEntityManager();
switch($this->objectType)
{
case 'video':
return $em->getRepository('fdj2012AdminBundle:Video')->find($this->objectId);
break;
case 'default':
return false;
break;
}
}
如何在我的实体中使用 entityManager ?
【问题讨论】:
-
Using EntityManager inside Doctrine 2.0 entities 的可能重复项。您的实体不应该知道实体管理器,而是您应该在需要时将所需的任何数据/服务传递给您的实体。
-
我从 twig 模板中得到了这个......但我会加深它。谢谢
标签: symfony doctrine-orm entity entitymanager