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

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

问题描述

如何设置 HTML 属性为< input> 使用 FormBuilder Symfony2中



$ p
$ b

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

))

{{form_widget(form.birthdate)}}

我希望这个输入字段的属性 class 设置为 日历 您可以从树枝模板执行此操作:

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

来自 HTT p://symfony.com/doc/current/book/forms.html#rendering-each-field-by-手


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

Something like this:

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

 {{ form_widget(form.birthdate) }}

I want this inputfield with the attribute class set to calendar

解决方案

You can do this from the twig template:

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

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

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

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