我遇到了问题。我创建了一个表单类并为我的实体设置了一些断言。Symfony2 form.error字段不起作用
但现在我想呈现错误。 我得到了全局错误的form_erros,但不是字段。
下面的代码:
控制器
public function addAction(Request $request){
$news = new news();
$form = $this->createForm(new NewsType(),$news);
$form->handleRequest($request);
if ($form->isValid()) {
echo "YEPP";
}
return array('form' => $form->createView());
}
Formclass
$builder
->add('unpublic','checkbox',array(
'required' => false))
->add('unactive','checkbox',array(
'required' => false))
->add('untitle','text',array(
'required' => true))
查看
<div class="form-group">
{{ form_label(form.untitle,'Titel*',{ 'label_attr': {'class': 'col-sm-2 control-label'}}) }}
<strong>{{ form_errors(form.untitle) }}</strong>
<div class="col-sm-10">
{{ form_widget(form.untitle, {'attr': {'class' : 'form-control'} }) }}
{{ form_errors(form.untitle) }}
</div>
</div>
实体
个/**
* @var string
*
* @ORM\Column(name="UNTITLE", type="string", length=255)
*
* @Assert\NotBlank()
* @Assert\Type("Text")
*
*/
private $UNTITLE;
非常感谢
嘿感谢您的帮助。是不是error_bubbling默认= true? – Chris
我试图 - >加( 'untitle', '文本',阵列( \t \t \t \t \t 'error_bubbling' \t =>真, \t \t \t \t \t '必要'=>真)) \t \t \t - >加( 'untext', '文本区域',阵列( \t \t \t \t \t 'error_bubbling' \t =>真, \t \t \t \t \t '必要'=>真)) \t \t \t - >加( 'unimage', '文件') \t \t \t - >加( 'undate', '日期',阵列( \t \t \t \t \t '插件'=> 'single_text', \t \t \t \t \t '格式'=> 'DD.MM.YYYY', \t \t \t \t \t 'error_bubbling' \t => true, 但它不工作:( – Chris
{{form_row(form.name)}}既没有工作也没有工作 – Chris