设置symfony 2表单字段的名称属性 [英] Setting name attribute of symfony 2 form field

查看:125
本文介绍了设置symfony 2表单字段的名称属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在symfony 2中设置渲染字段的name属性?



预期输出:

 < input type =textname =testvalue =test/> 

以这种方式呈现字段

  {{form_widget(form.test,{'attr':{'name':'test'}})}} 

绝对不行。



输出仍然是

 < input type =textname =form [test]value =test/> ;. 

有没有办法动态设置name属性或id属性?

解决方案

< input type =textname =form [测试]value =test/>

已经有 test 作为名称。当然,在你的情况下,仍然存在名为 form 的根表格名称。删除这个不是真正的建议,因为当你读取填充表单数据的请求时,你可以通过它的表单名称来识别表单。 阅读 [Form]启用空根表单名称 https://github.com/symfony/symfony/pull/2936


How to set name attribute of rendered field in symfony 2?

Expected output:

     <input type="text" name="test" value="test" />

Rendering the field this way

     {{ form_widget(form.test, { 'attr': {'name': 'test'} }) }}

definitely does not work.

Output is still

     <input type="text" name="form[test]" value="test" />.

Is there any way to set the name attribute or id attribute dynamically? Thank you.

解决方案

<input type="text" name="form[test]" value="test" />

already has test as name. Of course there is still the root form name called form in your case. Removing this is not really recommended, because when you read the request to populate form data you can identify the form by its form name.

Read [Form] Enable empty root form name https://github.com/symfony/symfony/pull/2936

这篇关于设置symfony 2表单字段的名称属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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