2013-02-14 225 views
7

我想要做的並不難。這是我第一個關於symfony的項目,它確實令人困惑。FOSUserBundle註冊自定義

我正在使用FOSUSerbundle。我不想有一個登錄和註冊波紋管/login/registration

所以我做了一個捆綁,這是FOSUSerbundle的孩子......它覆蓋了它的樹枝。

我有:: base.html.twig其中我包括header.html.twig和那裏我有:{% render 'FOSUserBundle:Security:login' %}其中呈現我的teplate(overos的FOS之一)工程gr8。即使提交之後的錯誤都在:: base模板下面的「/」路徑上呈現。

#Security.yml 
    form_login: 
     check_path: /login_check 
     login_path:/
     provider: fos_userbundle 

工程很好。

我需要爲我的註冊完全一樣。

所以在::base我包括welcome_page.html.twig,我的代碼{% render 'FOSUserBundle:Registration:register' %}有我在我的rewrited模板:WelcomePageBundle:Registration:register.html.twig這一點:

{% block fos_user_content %} 
{% include "FOSUserBundle:Registration:register_content.html.twig" %} 
{% endblock fos_user_content %}[/code] 

其中還包括從我rewrited包: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> 

一切都像一個魅力......所有的文件都包含在內並顯示爲greate。但現在問題出現了。

當我去的路線/register

(這是從FOS束基本路線)

<route id="fos_user_registration_register" pattern="/register"> 
    <default key="_controller">FOSUserBundle:Registration:register</default> 
</route> 

...填寫數據,然後點擊提交...它的工作原理。將顯示錯誤或登記更迭..

但是,當我從我的路線/,其中登記控制器被渲染(渲染OK)提交表單需要我來這條路線:/register這是正常的行爲,因爲這條路徑:

<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" id="register_form"> 

...本網站不通過任何擴展,從而有錯誤的白色網頁上它只是乾淨的形式... OK

但我怎麼能可能使工作這種形式顯示錯誤和成功對我::基地模板喜歡登錄?並不去/register路線?我試着替換/register/,它將我帶到我的::base模板(就像登錄我一樣)。

#security.yml 
form_login: 
    check_path: /login_check 
    login_path:/
    provider: fos_userbundle 

但顯示沒有任何錯誤或成功的...

難道有誰知道解決辦法?

+0

您是否試圖更改包中包含registration.xml的fos_user_register路由並將其作爲(/路由)的前綴而不是/ register?看起來你剛剛創建了另一條指向註冊控制器的路由。 – 2013-02-14 22:04:22

+0

你有沒有得到這個工作正常?瓦迪姆的建議是爲你解決問題的嗎? – AMP 2013-05-16 13:38:32

回答

4

,可以找到關於如何在 http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_controllers.html

覆蓋默認FOSUserBundle控制器爲您的主頁,並把請求轉發(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(), 
     )); 
    } 
}