Interlated
Interlated

Reputation: 5926

How to use Symfony 2.7 ChoiceType with php 5.4?

I am trying to update Symfony to the 2.7 API for choiceList. The symfony manual has the example:

$builder->add('isAttending', ChoiceType::class, array(

Which for php 5.4 I translated to

$builder->add('graduatedSince', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(

However, I get a "Could not load type" error. What is the syntax?

Upvotes: 1

Views: 340

Answers (1)

fcpauldiaz
fcpauldiaz

Reputation: 423

The syntax for Symfony 2.7 is

$builder->add('isAttending', 'choice', array(
    'choices'  => array(
        'Maybe' => null,
        'Yes' => true,
        'No' => false,
    ),
    // *this line is important*
    'choices_as_values' => true,
));

Here is the documentation

Upvotes: 2

Related Questions