2011-11-25 33 views
6

在Symfony2的表單中使用Date字段時,它們顯示在三個不同的選擇框中。 喜歡的東西:如何在Symfony2中以日期字段的全文顯示月份?

dd/mm/YYYY 

我們希望做的是在文本JanuaryFebruary顯示幾個月....代替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

回答

8

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

UPDAT E

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

你可以舉一個例子使用我在問題中添加的代碼嗎? –

+0

謝謝,爲了您的快速回答,但我已經嘗試過了,而'F'並沒有被Symfony解釋。 –

+0

這一定是因爲'date()'實際上沒有被使用。這個類:http://www.php.net/manual/en/class.intldateformatter.php被用來代替 – greg0ire

相關問題