在 symfony 2 中自定义日期表单自定义、表单、日期、symfony

由网友(﹏ /巨☉蟒)分享简介:我正在尝试使用 symfony2 和 twig 更改 date_widget.默认情况下,年份字段有 10 年选项,例如今天日期之前的 5 年和之后的 5 年.我想要直到现在的几年.我怎样才能改变它?我已经看过 'form_div_layout.html.twig' 但我发现它不是这个地方.I am trying t...

我正在尝试使用 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

(已编辑)

阅读全文

相关推荐

最新文章