【问题标题】:Override ProfileController FOSUserBundle in Symfony 2.3在 Symfony 2.3 中覆盖 ProfileController FOSUserBundle
【发布时间】:2014-05-09 01:54:42
【问题描述】:

那里,我正在尝试覆盖 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');

但还是失败了……

有什么帮助吗?

谢谢!

【问题讨论】:

    标签: symfony symfony-2.3


    【解决方案1】:

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

    调用 $this->container->get('templating')->renderResponse() 时遇到什么错误?

    【讨论】:

    • 在这种情况下,我收到此错误:错误:调用 D:\xampp\htdocs\projects\myproject\src\XxX\ 中的未定义方法 XxX\MyBundle\Controller\ProfileController::get() MyBundle\Controller\ProfileController.php 第 16 行...是 renderResponse() 的同一行
    • 好吧,我修复了错误,当我试图将变量发送到视图时,我试图访问实体管理器。谢谢!
    猜你喜欢
    • 2014-04-08
    • 1970-01-01
    • 2016-10-01
    • 2020-11-11
    • 1970-01-01
    • 2014-01-19
    • 1970-01-01
    • 2019-03-13
    • 2013-02-17
    相关资源
    最近更新 更多