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

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

问题描述

如何使用 FormBuilderHTML class 属性设置为表单 Symfony2 ?

How can I set the HTML class attribute to a form <input> using the FormBuilder in Symfony2 ?

像这样:

->add('birthdate', 'date',array(
      'input' => 'datetime',
      'widget' => 'single_text',
      'attr' => array(
          'class' => 'calendar'
      )
 ))

 {{ form_widget(form.birthdate) }}

我希望这个 input 字段的属性 class 设置为 calendar

I want this inputfield with the attribute class set to calendar

推荐答案

您可以从 twig 模板执行此操作:

You can do this from the twig template:

{{ form_widget(form.birthdate, { 'attr': {'class': 'calendar'} }) }}

来自 http://symfony.com/doc/current/book/forms.html#rendering-each-field-by-hand

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

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