Symfony2-form_start函数在树枝中自定义 [英] Symfony2 - form_start function customise in twig
问题描述
表单助手form_start
和form_end
在树枝中很有用:
Form helpers form_start
and form_end
are useful in twig:
{{ form_start(form) }}
{{ form_end(form) }}
我可以自定义一些参数,例如method
或action
.但是我需要自定义其他参数,例如class
或添加form-enctype
.
I can customise some parameters like the method
or the action
. But I need to customise others parameters like the class
or add the form-enctype
.
我可以这样做吗?我应该将其设置为FormType.php
吗?
Can I do it? Should i set up it into the FormType.php
?
从现在开始,我只是尝试将自定义的值添加到twig
函数中,如下所示:
Since now I simply try to add my customised value to the twig
function like below:
{{ form_start(form, {'class': 'myclass', 'action': 'myaction'}) }}
// fields...
{{ form_end(form, {'render_rest': true}) }}
但是在这种情况下,例如,class
不会出现.
But in this case, for example, the class
does not appear.
推荐答案
由于form_start
具有由于class
并不代表有效的变量名.您需要使用attr
属性将您的类指定为key/value
数组.
And as class
doesn't represent a valid variable name. You need to specify your class as a key/value
array using the attr
attribute.
然后,尝试...
{{ form_start(form, {'class': 'myclass', 'action': 'myaction', 'attr': {'class': 'your_class_name'}}) }}
也...
-
您应该确保正确定义了Type文件,以便让
form_start
助手设置正确的form-enctype
.
从Symfony 2.3开始不推荐使用form_enctype(formView)
帮助器.
The form_enctype(formView)
helper is deprecated since Symfony 2.3.
这篇关于Symfony2-form_start函数在树枝中自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!