且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Symfony2 - 调用未定义的方法getDoctrine()覆盖FOSUserBundle的ProfileController

更新时间:2023-11-19 21:11:22

将此别名方法添加到控制器修复问题:

  public function getDoctrine()
{
return $ this-> container-> get('doctrine');
}


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.

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

public function getDoctrine()
{
    return $this->container->get('doctrine');
}