2016-02-17 40 views
0

我有一個重複的字段類型,當我訪問頁面時不會呈現。
我有我的控制器這個方法:Symfony3 - 重複字段類型不呈現

/** 
* @Route("/{token}", name="pass_reset_form") 
* 
* Function to reset password. 
*/ 
public function ResetAction(Request $reset, $token) 
{ 
    $form = $this->createForm(ResetformType::class); 
    $form->handleRequest($reset); 
    if ($form->isSubmitted() && $form->isValid()) { 
     $em = $this->getDoctrine()->getManager(); 
     $user = $em->getRepository('VendorMyBundle:Logins')->findByToken($token); 
     if (!empty($user)) 
     { 
      // encode password and update in the DB 
      $password = $this->get('security.password_encoder') 
      ->encodePassword($user[0], $form["newPassword"]->getData()); 
      $user[0]->setPassword($password); 
      $em->flush(); 
      $this->addFlash('notice', 'The password has been successfully reset. You can now login.'); 
      return $this->redirectToRoute('login_route'); 
     } 
    } 
    return $this->render(
     'VendorMyBundle:Default:resetEntry.html.twig', 
     array('form' => $form->createView()) 
      ); 
} 

,這是ResetformType:

namespace Vendor\MyBundle\Form; 

use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilderInterface; 
use Symfony\Component\Form\Extension\Core\Type\RepeatedType; 
use Symfony\Component\Form\Extension\Core\Type\PasswordType; 

class ResetformType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder->add('newPassword', RepeatedType::class, array(
      'type' => PasswordType::class, 
      'invalid_message' => 'The password fields must match.', 
      'required' => true, 
      'first_options' => array('label' => 'Password'), 
      'second_options' => array('label' => 'Repeat Password'), 
     )); 
    } 
} 

,這是標準的枝杈代碼:

{% block body1 %} 
    {{ form_start(form) }} 
     <button type="submit">Reset Password</button> 
    {{ form_end(form) }} 
{% endblock %} 

每當我訪問路線這使我對該呈現的視圖,我只看到表單按鈕。我查看頁面源代碼,所有HTML代碼都是表單按鈕和一個隱藏的表單標記字段。

<form name="resetform" method="post"> 
    <button type="submit">Reset Password</button> 
    <input type="hidden" id="resetform__token" name="resetform[_token]" value="2NJ7Uht8bgVUV27GnD4FHrCOjTFCIXXQyraJkG4jSmc" /> 
</form> 

我在想什麼?

+1

你有沒有嘗試過其他領域,看看如果這些也不起作用?您是否嘗試過使用'{{form_row(form.newPassword)}}'手動渲染字段? –

+0

@JasonRoman哈哈,這有多奇怪?!有效。爲什麼它不適用於標準形式的顯示枝條塊? –

+1

我會嘗試清除緩存,然後嘗試使用您的原始方法...'form_end(form)'應該已經自動將該字段放入您中,因爲您沒有指定'render_rest'爲假 –

回答

0

回答任何碰到同一問題的人。
要麼清除您的緩存或分別具體渲染字段,在我的情況下:
{{ form_row(form.newPassword) }}