FOSUserBundle覆盖问题

时间:2014-07-29 14:55:25

标签: symfony fosuserbundle

我有一个问题,我正在搜索interwebz,但没有找到解决方案!

我的问题是:我想覆盖注册并在我的视图中(或在覆盖视图中)显示fosuserbundle的注册表单。不工作......

总是讲同样的故事;

复制到:

应用程序/资源/ FOSUserBundle /视图/......

我已经做到了!

我已经覆盖了一个适用于注册的控制器:

<?php

namespace CS\UserBundle\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\RegistrationController as BaseController;
use Symfony\Component\HttpFoundation\Request;


class RegistrationController extends BaseController
{
    public function registerAction(Request $request)
    {
        $form = $this->container->get('fos_user.registration.form');
        $formHandler = $this->container->get('fos_user.registration.form.handler');
        $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');

        $process = $formHandler->process($confirmationEnabled);
        if ($process) {
            $user = $form->getData();

            if ($confirmationEnabled) {
                $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
                $route = 'fos_user_registration_check_email';
            } else {
                $this->authenticateUser($user);
                $route = 'fos_user_registration_confirmed';
            }

            $this->setFlash('fos_user_success', 'registration.flash.user_created');
            $url = $this->container->get('router')->generate($route);

            return new RedirectResponse($url);
        }

        return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:register.html.'.$this->getEngine(), array(
            'form' => $form->createView(),
        ));
    }
}

路由:

register:
    pattern: /register
    defaults: { _controller: CSUserBundle:Registration:register }

这是我的覆盖目录:

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您只想在模板中创建注册表单,则只需覆盖 Resources / views / layout.html.twig 即可。它比超控控制器,路线等更简单 它是FOSUserBundle的总体布局。 Here您可以找到有关如何操作的详细说明。