2011-11-25 12 views
6

Al usar el campo Fecha en formularios con Symfony2, se muestran en tres cuadros de selección diferentes. Algo así como:¿Cómo se muestran los meses en texto completo para los campos de Fecha en Symfony2?

dd/mm/YYYY 

Lo que nos gustaría hacer es visualizar los meses en el texto January, February .... en lugar de 1,2,3 ...

cómo forzar la pantalla en su totalidad texto para el menú desplegable de meses?

EDIT: Aquí está el código que utilizo en mi clase de formulario:

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

Edit2: Imagen que muestra F

enter image description here

Respuesta

8

mirar el código de la clase DateType, tiene una opción de formato:

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

updat E

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

¿Podría dar un ejemplo utilizando el código que agregué en la pregunta? –

+0

Gracias, por su respuesta rápida, pero ya lo intenté, y la 'F' no está siendo interpretada por Symfony. –

+0

Esto debe ser porque 'date()' en realidad no se usa. Esta clase: http://www.php.net/manual/en/class.intldateformatter.php se usa en su lugar – greg0ire

Cuestiones relacionadas