2016-02-17 41 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) }}