20

整个错误是由于标题最大字符而被替换为 3 个点的任务命名空间Symfony\Component\Form 。

因此,我正在按照文档中提供的步骤进行操作,但我无法找到我遇到的错误的来源。如果有人可以提供帮助,我将不胜感激。

这是我的AuthController中的方法

/**
 * @Route("/register", name="registrationPage")
 */
public function showRegistrationPage(Request $request)
{
    return $this->render('auth/register.html.twig', [
        'register_form' => $this->createForm(RegisterType::class, (new UserInformation()))
    ]);
}

这是方法,我在其中声明表单

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('firstname', TextType::class, ['attr' => ['class' => 'form-control']])
        ->add('secondname', TextType::class, ['attr' => ['class' => 'form-control']])
        ->add('email', EmailType::class, ['attr' => ['class' => 'form-control']])
        ->add('password', PasswordType::class, ['attr' => ['class' => 'form-control']])
        ->add('password_confirmation', PasswordType::class, [
            'label' => 'Confirm Password',
            'attr' => ['class' => 'form-control'],
            'mapped' =>false
        ])
        ->add('Register', SubmitType::class, ['attr' => ['class' => 'btn btn-primary']]);

}
4

2 回答 2

24
/**
 * @Route("/register", name="registrationPage")
 */
public function showRegistrationPage(Request $request)
{
    $form = $this->createForm(RegisterType::class, (new UserInformation()));

    return $this->render('auth/register.html.twig', [
        'register_form' => $form->createView()
    ]);
}

http://symfony.com/doc/current/forms.html#building-the-form

于 2017-06-13T18:23:56.690 回答
4

缺少的部分是 createView() 方法

/**
 * @Route("/register", name="registrationPage")
 */
public function showRegistrationPage(Request $request)
{
    return $this->render('auth/register.html.twig', [
        'register_form' => $this->createForm(RegisterType::class, (new UserInformation()))->createView()
    ]);
}
于 2019-03-26T13:50:24.703 回答