FOSuserBundle 覆盖控制器

FOSuserBundle override controller

在 Symfony 3.4 中将更多变量传递给 FOSUserBundle 设置 twig 模板 (Profile/show_content.html.twig) 的正确方法是什么?

我基本上想重写 showAction() method 并传递超过 user 的变量 ti twig 模板。

我试着关注这个tutorial。它似乎不再适用于 Symfony 3.4

我的方法(可能还有更好的方法)是简单地创建一个新控制器,其中包含到原始 'show route' 的路由,以及我要传递的变量。这是 showAction() 的示例,带有一个额外的变量 rendered_address:

namespace App\Controller;

use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class ProfileController extends Controller
{
    /**
    * Show the user.
    * @Route("/profile/show")
    */
    public function showAction()
    {
    $user = $this->getUser();
    if (!is_object($user) || !$user instanceof UserInterface) {
        throw new AccessDeniedException('This user does not have access to this section.');
    }

    $address = $this->getUser()->renderAddress(); // here is get my variable

    return $this->render('@FOSUser/Profile/show.html.twig', array(
        'user' => $user,
        'rendered_address' => $address // here is pass my variable
    ));
    }
}