在表格中使用日期字段与Symfony2时,它们显示在三个不同的选择框中.就像是 :
dd/mm/YYYY
Run Code Online (Sandbox Code Playgroud)
我们想要做的是用文字显示月份January
,February
而不是1,2,3 ......
如何在月份下拉列表中强制显示全文?
编辑:这是我在表单类中使用的代码:
$builder->add('dateOfBirth', 'birthday', array(
'format' => 'dd - MM - yyyy',
'widget' => 'choice',
'years' => range(date('Y'), date('Y')-70)
));
Run Code Online (Sandbox Code Playgroud)
EDIT2:显示F的图像
查看DateType类的代码,它有一个格式选项:
$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
);
Run Code Online (Sandbox Code Playgroud)
UPDATE
$builder->add('dateOfBirth', 'birthday', array(
'format' => 'dd - MMMM - yyyy',
'widget' => 'choice',
'years' => range(date('Y'), date('Y')-70)
));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5540 次 |
最近记录: |