Symfony3 - 重复的FieldType不呈现

时间:2016-02-17 21:50:12

标签: symfony-forms symfony

我访问页面时没有呈现的重复字段类型 我在我的控制器中有这个方法:

/**
 * @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 个答案:

答案 0 :(得分:0)

回答任何碰到同样问题的人。
清除缓存或专门渲染字段,在我的情况下使用:
{{ form_row(form.newPassword) }}