1
當我重寫FOSUserBundle的ProfileController
並添加這些行:Symfony2中 - 調用未定義的方法getDoctrine()覆蓋FOSUserBundle的ProfileController可
$em = $this->getDoctrine()->getManager();
$resultat = $em->getRepository('PublishDemandsBundle:Demands')->findAll();
我收到以下錯誤:
Call to undefined method Register\UserBundle\Controller\ProfileController::getDoctrine() in ProfileController.php.
你的ProfileContr怎麼樣oller看起來像?看起來你沒有擴展默認的控制器類。 –
FOSUserBundle的ProfileController擴展['ContainerAware'](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Controller/ProfileController.php#L29)而不是['Controller'](https://github.com/的symfony/symfony的/斑點/主/ SRC/Symfony的/捆綁/ FrameworkBundle /控制器/ Controller.php這樣)。因此,您需要:使用'$ this-> container-> get('doctrine')'或添加['getDoctrine()'](https://github.com/symfony/symfony/blob/master/src /Symfony/Bundle/FrameworkBundle/Controller/Controller.php#L218)自己重寫到ProfileController。 – nifr