Symfony2-form_start函数在树枝中自定义 [英] Symfony2 - form_start function customise in twig

查看:95
本文介绍了Symfony2-form_start函数在树枝中自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表单助手form_startform_end在树枝中很有用:

Form helpers form_start and form_end are useful in twig:

{{ form_start(form) }}
{{ form_end(form) }}

我可以自定义一些参数,例如methodaction.但是我需要自定义其他参数,例如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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆