Symfony2-将类添加到表单标签 [英] Symfony2 - Add class to form tag
本文介绍了Symfony2-将类添加到表单标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以将类添加到<input>
字段中,如下所示:
I know I can add classes to <input>
fields in a form like this:
->add('foo', 'text', array('attr' => array('class' => 'foo-class'));
但是如何将类添加到<form>
标记?
but how could I add a class to a <form>
tag?
推荐答案
为此,有两种解决方案,您可以在控制器中执行,也可以在视图中执行.
For this, there's 2 solutions, either you do it in your controller or your view.
1)在您的控制器中:
1) In your controller :
$form = $this->createForm(new FormType(), $data, ['attr' => ['class' => 'myClass']]);
2)在您看来(嫩枝):
2) In your view (Twig) :
{{ form_start(form, { 'attr' : { 'class': 'myClass' } }) }}
这篇关于Symfony2-将类添加到表单标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文