2011-11-25 13 views
6

Używając pola Data w formularzach z Symfony2, są one wyświetlane w trzech różnych polach wyboru. Coś jak:Jak wyświetlić miesiące w pełnym tekście dla pól dat w Symfony2?

dd/mm/YYYY 

Co chcielibyśmy zrobić to wyświetlenie miesięcy w tekście January, February .... zamiast 1,2,3 ...

Jak wymusić wyświetlanie w całości tekst na liście miesięcy?

EDIT: Oto kod używam w mojej klasie forma:

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

EDIT2: obraz przedstawiający F

enter image description here

Odpowiedz

8

spojrzeć na kod klasy DateType, posiada opcja formatu:

$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

Możesz podać przykład używając kodu dodanego w pytaniu? –

+0

Dzięki za szybką odpowiedź, ale już to wypróbowałem, a "F" nie jest interpretowane przez Symfony. –

+0

Musi to być spowodowane tym, że 'date()' w rzeczywistości nie jest używane. Ta klasa: http://www.php.net/manual/en/class.intldateformatter.php jest używana zamiast tego – greg0ire

Powiązane problemy