自定义日期表在symfony 2 [英] Customizing date form in 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屋!