Symfony2 - 调用未定义的方法getDoctrine()覆盖FOSUserBundle的ProfileController [英] Symfony2 - Call to undefined method getDoctrine() when overriding FOSUserBundle's ProfileController

查看:150
本文介绍了Symfony2 - 调用未定义的方法getDoctrine()覆盖FOSUserBundle的ProfileController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我覆盖FOSUserBundle的 ProfileController 并添加以下行:

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

我收到以下错误:


调用未定义的方法

ProfileController.php中的Register\UserBundle\Controller\ProfileController :: getDoctrine()。



解决方案

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

  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');
}

这篇关于Symfony2 - 调用未定义的方法getDoctrine()覆盖FOSUserBundle的ProfileController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆