Forms Symfony未在细枝中显示错误

Forms Symfony未在细枝中显示错误,forms,error-handling,twig,symfony-2.1,Forms,Error Handling,Twig,Symfony 2.1,我对Symfony2框架还相当陌生,我很难在twig中显示错误。 使用$form->createFormBuilder()->add() 当我运行{{form_errors(form)}}时,不会显示任何内容,我也不确定自己做错了什么 public function massEmailAction(Request $request) { $data['errors'] = ''; $form = array('message'=>'test', 'single_email_

我对Symfony2框架还相当陌生,我很难在twig中显示错误。 使用
$form->createFormBuilder()->add()

当我运行
{{form_errors(form)}}
时,不会显示任何内容,我也不确定自己做错了什么

public function massEmailAction(Request $request)
{
    $data['errors'] = '';
    $form = array('message'=>'test', 'single_email_val'=>'', 'send_to'=>'');
    $form = $this->createFormBuilder($form)
    ->add('message', 'textarea', array('attr'=>array('style'=>"width: 800px; height: 500px;")))
    ->add('single_email_val', 'text', array('label'=>'Single Email', 'required'=>false, 
                                                            'constraints'=>array(
                                                               new NotBlank(),
                                                               new Length(array('min' => 3)),


                                                    ),
                                            'invalid_message'=>'email not valid',
                                            'error_bubbling'=>true,
                                            ))
    ->add('send_to', 'choice', array('choices'=>array(''=>'Select',
                                                      'single_email'=>'Send to Single Email',
                                                      'mass_email'=>'Send to All'
                                                    ),
                                                    'required'=>false,

    ))
    ->getForm();

    $data['form'] = $form->createView();

    if($request->isMethod('POST'))
    {
        $emailConstraint = new NotBlank();
        $formData = $form->bind($this->getRequest());
        // Get form data
        $post = $formData->getData();
        echo $post['single_email_val'];

        if(!$form->isValid())
        {

            echo 'not valid';
            //print_r($this->getErrorMessages($form));
            print_r($this->getErrorMessages($form));
            $data['errors'] = $this->getErrorMessages($form);
            // print_r($form->getErrors());
            //echo $form->getErrorsAsString();
        }
        else
        {

        }

    }

    return $this->render('TmarketMarketingBundle:Default:massEmail.html.twig', $data);
}
按这个顺序试一试

**$data['form'] = $form->createView();**
return $this->render('TmarketMarketingBundle:Default:massEmail.html.twig', $data);

在绑定和验证数据之前,您将获得表单视图

请显示us$form->GetErrorsString();输出