2016-10-28 21 views
1

如何獲取在我的ChoiceType中選擇的項目的值。我想在我的樹枝中以其他形式使用它。 這是我buildForm:BuildForm Symfony 2 - 在ChoiceType中獲取所選值

$builder->add('number', ChoiceType::class, array(
 
      'choices' => array(
 
       '1'=>'Uns', 
 
       '2'=>'Deux', 
 
       '3'=>'Trois', 
 
      ), 
 
      'required' => true 
 
     ));

我想做的事:

{% if selectedValue == 1 %} 
 
    //do something 
 
{% endif%}

編輯: 在我看來,我有:

<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6"> 
 
      {{ form_widget(form.number) }} 
 
     </div>

如果我選擇了一個項目,我有理智最多:

<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6"> 
 
     selected : {{ form.number.vars.value }} 
 
     </div>

編輯2: enter image description here

如何我可以選擇VALU我choiceType電子

感謝

+0

的可能的複製[Symfony的 - 表項爲純文本(http://stackoverflow.com/questions/40227349/symfony-form-item-as-plain-text) – yceruto

回答

1

您可以vars訪問表單屬性值。如實施例:

{% if form.number.vars.value == 1 %} 
    //do something 
{% endif%} 
+0

利瑪>可以你看我的編輯問題:)。結果沒有任何結果 – ALFA