Symfony2 - Call to undefined method getDoctrine()

2019-08-08 03:24发布

When I override FOSUserBundle's ProfileController and add these lines:

  $em = $this->getDoctrine()->getManager();
  $resultat = $em->getRepository('PublishDemandsBundle:Demands')->findAll();

I get the following error:

Call to undefined method Register\UserBundle\Controller\ProfileController::getDoctrine() in ProfileController.php.

1条回答
叼着烟拽天下
2楼-- · 2019-08-08 04:19

Adding this alias-method to the controller fixed the issue:

public function getDoctrine()
{
    return $this->container->get('doctrine');
}
查看更多
登录 后发表回答