如何在Symfony2中的“日期"字段中以全文形式显示月份? [英] How to display months in full text for Date fields in Symfony2?
本文介绍了如何在Symfony2中的“日期"字段中以全文形式显示月份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在带有Symfony2的表单中使用日期"字段时,它们将显示在三个不同的选择框中. 像这样的东西:
When using Date field in forms with Symfony2, they are displayed in three different select boxes. Something like :
dd/mm/YYYY
我们要做的是在文本January
,February
....中显示月份,而不是1,2,3 ...
What we would like to do is display the months in text January
, February
.... instead of 1,2,3...
如何在月份下拉列表中强制显示全文?
How to force display in full text for the months dropdown ?
这是我在表单类中使用的代码:
EDIT : Here is the code I use in my form class :
$builder->add('dateOfBirth', 'birthday', array(
'format' => 'dd - MM - yyyy',
'widget' => 'choice',
'years' => range(date('Y'), date('Y')-70)
));
显示F的图像
推荐答案
看一下DateType类的代码,它具有一个格式选项:
Look at the code of the DateType class, it has a format option:
$allowedFormatOptionValues = array(
\IntlDateFormatter::FULL,
\IntlDateFormatter::LONG,
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::SHORT,
);
// If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
if (!in_array($format, $allowedFormatOptionValues, true)) {
if (is_string($format)) {
$defaultOptions = $this->getDefaultOptions($options);
$format = $defaultOptions['format'];
$pattern = $options['format'];
} else {
throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
}
}
$formatter = new \IntlDateFormatter(
\Locale::getDefault(),
$format,
\IntlDateFormatter::NONE,
\DateTimeZone::UTC,
\IntlDateFormatter::GREGORIAN,
$pattern
);
更新
$builder->add('dateOfBirth', 'birthday', array(
'format' => 'dd - MMMM - yyyy',
'widget' => 'choice',
'years' => range(date('Y'), date('Y')-70)
));
这篇关于如何在Symfony2中的“日期"字段中以全文形式显示月份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文