簡體   English   中英

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

[英]How to display months in full text for Date fields in Symfony2?

在表格中使用日期字段與Symfony2時,它們顯示在三個不同的選擇框中。 就像是 :

dd/mm/YYYY

我們想要做的是在JanuaryFebruary月的文本中顯示February ....而不是1,2,3 ......

如何在月份下拉列表中強制顯示全文?

編輯:這是我在表單類中使用的代碼:

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

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

UPDATE

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM