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

When using the Date field in forms with Symfony2, they appear in three different select boxes. Sort of:

dd/mm/YYYY 

We would like to show months in the text January , February .... instead of 1,2,3 ...

How to force display in full text for a drop-down list of months?

EDIT: Here is the code that I use in my form class:

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

EDIT2: Image showing F

enter image description here

+6
source share
1 answer

Look at the DateType class code, it has a format option:

 $allowedFormatOptionValues = array( \IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, ); // If $format is not in the allowed options, it 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) )); 
+8
source

Source: https://habr.com/ru/post/902389/


All Articles