2016-12-29 3 views
0

Symfony documentation는이 같은 사용 ChoiceType를 사용하는 것을 말한다 값 :심포니 폼 ChoiceType는

use Symfony\Component\Form\Extension\Core\Type\ChoiceType; 

$builder->add('titre', ChoiceType::class, array(
    'choice_value' => array(
     'Pr', 'Dr', 'Mr', 'Mrs' 
    ), 
)) 

어떻게하면됩니까?

내가 할 수 없다면 뒤에있는 좋은 이유는 무엇입니까?

답변

1

당신은 array_combine와 같은 키/값 배열을 만들 시도 할 수 있습니다 :

use Symfony\Component\Form\Extension\Core\Type\ChoiceType; 

$choices = array('Pr', 'Dr', 'Mr', 'Mrs'); 

$builder->add('isAttending', ChoiceType::class, array(
    'choices' => array_combine($choices, $choices), 
)); 
+0

좋아! 심포니 쉐어 (symfony-ish) 방법을 찾고 있었지만 이것이 잘 작동합니다 :-) –

1

A Symfony-ish way :

$builder->add('isAttending', ChoiceType::class, array(
    'choices' => array('Pr', 'Dr', 'Mr', 'Mrs'), 
    'choice_label' => function ($value) { return $value; }, 
));