代码之家  ›  专栏  ›  技术社区  ›  Joozty

FosUserBundle覆盖控制器

  •  0
  • Joozty  · 技术社区  · 6 年前

    把更多的变量传递给 FOSUserBundle 设置细枝模板( Profile/show_content.html.twig )在symfony 3.4?

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

    我试着跟着这个 tutorial . 它似乎不再适用于symfony 3.4

    1 回复  |  直到 6 年前
        1
  •  1
  •   Dirk J. Faber    6 年前

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