我怎样才能在存储库中使用条令查找方法


How can I use doctrine find method in repository

此代码在控制器中运行良好

$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('AcmeUserBundle:Child')->find($id);

现在我有自定义的Repository

我想知道如何在那里使用

function getUser()
{
    $em = $this->getEntityManager();
    $entity = $em->getRepository('AcmeUserBundle:Child')->find($id);
}

我是否还需要在Repository中使用getRepository

如果方法在Repository类中,那么您可以只使用$this

$enity = $this->find($id);