在 symfony 2 中自定义日期表单 [英] Customizing date form in symfony 2

查看:12
本文介绍了在 symfony 2 中自定义日期表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 symfony2 和 twig 更改 date_widget.默认情况下,年份字段有 10 年选项,例如今天日期之前的 5 年和之后的 5 年.我想要直到现在的几年.我怎样才能改变它?我已经看过 'form_div_layout.html.twig' 但我发现它不是这个地方.

I am trying to alter the date_widget using symfony2 and twig. By default a field of years has 10 year options, e.g. 5 years before and 5 years after the today date. I would like just the years until now. How can I change it? I have already looked at 'form_div_layout.html.twig' but I see that it's not the place of this.

推荐答案

在构建日期小部件时使用年"选项.例如:

Use the 'years' option when building your date widget. For example:

$builder->add('foobar_date','date', array(
    'years' => range(date('Y') -5, date('Y')),
));

有关如何配置日期小部件的更多信息:http://symfony.com/doc/current/reference/forms/types/date.html

More info on how to configure the date widget: http://symfony.com/doc/current/reference/forms/types/date.html

(已编辑)

这篇关于在 symfony 2 中自定义日期表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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