2014-07-04 15 views

回答

1

您可以使用類似如下定義的「標準時間」和「其他小時數」來替換默認的OptGroup。

$category_choices = array(
      'Standard Hours' => array(
      2 => '2', 
      4 => '4', 
      6 => '6', 
      8 => '8' 
     ), 
      'Other Hours' => array(
      1 => '1', 
      3 => '3', 
      5 => '5', 
      7 => '7', 
      9 => '9', 
      10 => '10' 
     ) 
     ); 

     $builder 
      ->add('hours', 'choice', array(
       'choices' => $category_choices 
     )); 

或者,如果你不想OPTGROUP標籤可言,只有選擇項,就可以直接跳過了對嵌套數組乾脆。

$builder 
    ->add('hours', 'choice', array(
    'choices' => array(
     1 => '1', 
     2 => '2', 
     3 => '3', 
     4 => '4' 
    ) 
)); 

在你的情況,你想要的東西,如:

$builder 
    ->add('hours', 'choice', array(
    'choices' => arrayFromParamsYML 
)); 
+0

感謝但對我來說,我想沒有OPTGROUP標籤可言,知道數組有來自params.yml因爲我用其價值有幾種不同的形式。任何想法 ? – erwandiep

+0

我的第二個代碼片段解釋瞭如何沒有opt組。 –

+0

非常感謝,它的工作原理。 – erwandiep