php - 如何在 Symfony2 中以全文显示日期字段的月份?

标签 php forms symfony

当在 Symfony2 的表单中使用日期字段时,它们会显示在三个不同的选择框中。 像这样的东西:

dd/mm/YYYY

我们想要做的是在 January, February.... 中显示月份,而不是 1,2,3...

如何强制显示月份下拉列表的全文?

编辑:这是我在表单类中使用的代码:

$builder->add('dateOfBirth', 'birthday', array(
    'format' => 'dd - MM - yyyy',
    'widget' => 'choice',
    'years' => range(date('Y'), date('Y')-70)
));

EDIT2:显示 F 的图像

enter image description here

最佳答案

看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
    );

更新

$builder->add('dateOfBirth', 'birthday', array(
    'format' => 'dd - MMMM - yyyy',
    'widget' => 'choice',
    'years' => range(date('Y'), date('Y')-70)
));

关于php - 如何在 Symfony2 中以全文显示日期字段的月份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8269519/

相关文章:

php - xampp 中的 Postgresql、phpMyAdmin

Angular Form 对浏览器自动填充无效

php - 为什么 Symfony 分析器在使用 Memcached 分析器存储时抛出 404?

symfony - Symfony Ajax Response显示缓存头

symfony - Dart Packages 文件夹不再存在我现在如何与 symfony 集成以进行开发

PHP 正则表达式 - 必须至少包含任意 2 个 UTF-8 字母

php - 在php中调用时如何将php变量传递到mysql存储过程

java - 一个 JSP 文件中的多个表单与不同的 Servlet 交互

javascript - 两个具有相同操作的提交按钮,其中一个为同一表单添加了功能/操作

php - MySQL 查询返回带有 AES_ENCRYPT 的空白字段