如何为Symfony2表单输入设置CSS ID属性 [英] How to set a CSS ID attribute to a Symfony2 form input

查看:75
本文介绍了如何为Symfony2表单输入设置CSS ID属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题类似于另一个问题.有解决方案设置CSS类的方法是将其添加到对FormBuilder :: add()的调用的第3个参数中:

This question is similar to another question. There the solution for setting the CSS class was to add it into the 3rd parameter of a call to FormBuilder::add():

->add('title', null, array('attr' => array('class'=>'span2')))

不幸的是,这不适用于设置CSS ID.当我这样做

Unfortunately, this does not work for setting the CSS id. When I do

->add('title', null, array('attr' => array('id'=>'title-field')))

...这被忽略.该ID仍然类似于namespace_formtype_field.

... this is ignored. The ID remains something like namespace_formtype_field.

如何设置CSS ID(如果有的话)?

How can I set the CSS ID, if at all?

推荐答案

我相信现在没有简单的答案.实际上,最接近的标记似乎实际上是通过使用 form主题化.谢谢 Michi 指出了这一点.

I am convinced now there is no easy answer. The closest seems to in fact change the markup by using form theming. Thank you Michi for pointing this way.

这篇关于如何为Symfony2表单输入设置CSS ID属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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