我使用Symfony 4.0框架我遇到了问题。我创建的表单没有问题,但我看不到form_errors()文本,它不起作用。
我在这段代码中哪里做错了?
我的控制器:
$user = new Users();
$form = $this->createFormBuilder($user)
->add('firstName', TextType::class, array('label'=> 'Name','error_bubbling' => false))
->add('lastName',TextType::class, array('label'=> 'Lastname','error_bubbling' => false))
->add('Email', EmailType::class, array('label' => 'Email','error_bubbling' => false))
->add('Password', RepeatedType::class, array(
'type' => PasswordType::class,
'error_bubbling' => false,
'invalid_message' => 'The password fields must match.',
'options' => array('attr' => array('class' => 'password-field')),
'first_options' => array('label' => 'Password','error_bubbling' => true),
'second_options' => array('label' => 'Repeat Password'),
))
->add('Save', SubmitType::class, array('label' => 'Register'))
->getForm();
$data['form'] = $form->createView();
$form->handleRequest($request);
$errors = $validator->validate($user);
if($errors->count() > 0){
$data['errors'] = $errors;
return $this->output('user/register',$data);
}
我创建的表单无法获得twig渲染。无法看到错误文字
.. html.twig:
{{ form_start(form) }}
{{ form_row(form) }}
{{ form_end(form) }}