在Symfony 2.3中覆盖ProfileController FOSUserBundle

时间:2014-05-09 01:54:43

标签: symfony symfony-2.3

那里,我试图覆盖FOSUSerBundle的ProfileController,我在尝试渲染模板时遇到错误,这是代码:

namespace XxX\MyBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class MyBundle extends Bundle
{
    public function getParent() 
    {
        return 'FOSUserBundle';
    }
}

然后,我尝试覆盖控制器:

<?php

namespace XxX\MyBundle\Controller;

use FOS\UserBundle\Controller\RegistrationController as BaseController;

class ProfileController extends BaseController
{
    public function myAction()
    {
        $userManager = $this->container->get('fos_user.user_manager');
        $user = $userManager->findUserByUsername($this->container->get('security.context')
                    ->getToken()
                    ->getUser());

        return $this->render('MyBundle:Profile:show.html.twig');
    }

}

我收到此错误:

Error: Call to undefined method XxX\MyBundle\Controller\ProfileController::render() in D:\xampp\htdocs\projects\alopatria\src\Jaguar\AloBundle\Controller\ProfileController.php line 16

我试过了:

return $this->container->get('templating')->renderResponse('MyBundle:Profile:show.html.twig');

但仍然失败......

请帮忙吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

FOSUserBundle-RegistrationController不会扩展SF2的Symfony \ Bundle \ FrameworkBundle \ Controller \ Controller,后者提供render()方法。 它只是实现了ContainerAware接口。

调用$ this-&gt; container-&gt; get(&#39; templating&#39;) - &gt; renderResponse()时会出现哪个错误?