我想做的不是什么难事。这是我关于symfony的第一个项目,它真的令人困惑。
我正在使用FOSUSerbundle。我不想在/login和/registration下面登录和注册
所以我做了一个包,这是FOSUSerbundle的孩子.它凌驾于树枝之上。
我有::base.html.twig,其中包括header.html.twig,还有:{% render 'FOSUserBundle:Security:login' %},它呈现了我的平板(覆盖了FOS ) works gr8。甚至在提交后的错误都是在::base模板bellow "/“路由上呈现的。
#Security.yml
form_login:
check_path: /login_check
login_path: /
provider: fos_userbundle效果很好。
我也需要做同样的注册工作。
因此,在::base中,我包括了welcome_page.html.twig,其中我编写了{% render 'FOSUserBundle:Registration:register' %}代码,在重新编写的模板下有:WelcomePageBundle:Registration:register.html.twig:
{% block fos_user_content %}
{% include "FOSUserBundle:Registration:register_content.html.twig" %}
{% endblock fos_user_content %}[/code]其中还包括我重新编写的包:WelcomePageBundle:Registration:register_content.html.twig:
{% for key, message in app.session.getFlashes() %}
<div class="{{ key }}">
{{ message|trans({}, 'FOSUserBundle') }}
</div>
{% endfor %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" id="register_form">
{{ form_widget(form) }}
{{ form_rest(form) }}
<input type="submit" class="registration_submit" value="{{ 'welcome_page.registration_box.register_submit'|trans }}"/>
</form>
<div class="v_pripade">
{{ 'welcome_page.registration_box.with_reg_problems'|trans }}
<span style='color: #fff568'>{{ 'welcome_page.registration_box.with_reg_problems_part2'|trans }}</span>
</div>一切都很有魅力..。所有的文件都包含在一起并显示得很好。但问题现在来了。
当我去/register路线的时候
(这是FOS包的基本路线)
<route id="fos_user_registration_register" pattern="/register">
<default key="_controller">FOSUserBundle:Registration:register</default>
</route>..。填写数据并单击submit..。它起作用了。显示错误或注册成功。
但是,当我从我的路由/提交表单时,注册控制器被呈现(呈现为ok),它将我的表单提交到这个路由:/register,这是正常的行为,因为这个路径:
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" id="register_form">..。这个网站没有任何扩展,所以它只是在白色页面上的干净形式错误..。好的
但是,如果在我的::基本模板(如登录)上显示错误和成功,我如何才能使此表单工作呢?不去/register路线吗?我尝试将/register替换为/,这让我找到了/模板(就像登录时一样)。
#security.yml
form_login:
check_path: /login_check
login_path: /
provider: fos_userbundle但所有的错误和成功都没有展现出来.
有人知道解决办法吗?
发布于 2013-04-09 21:16:03
您将在FOSUserBundle上找到关于如何覆盖默认controllers.html控制器的正式文档
为您的主页创建一个控制器,并将请求(http://symfony.com/doc/master/book/controller.html#forwarding)转发给FOSUserBundle注册控制器,或者在执行FOSUserBundle在注册时所做的任何操作之后,向您自己的控制器添加逻辑:
<?php
namespace Acme\UserBundle\Controller;
// Imports @route annotation
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class CustomRegistrationController extends BaseController {
/**
* @Route("/")
*/
public function register() {
$response = $this->forward('FOSUserBundle:Registration:register');
return $response;
}
}或
<?php
namespace Acme\UserBundle\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\RegistrationController as BaseController;
class RegistrationController extends BaseController
{
public function registerAction()
{
$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();
/*****************************************************
* Add new functionality (e.g. log the registration) *
*****************************************************/
$this->container->get('logger')->info(
sprintf('New user registration: %s', $user)
);
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(),
));
}
}https://stackoverflow.com/questions/14874504
复制相似问题