bili
bili

Reputation: 415

Symfony2 Array to string conversion

i'm working on symfony2 project and i get this exception. anybody have an idea on what is causing it ?

Notice: Array to string conversion in C:\wamp\www\EmploiPublic\vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList.php line 457

protected function fixIndex($index)
{
    if (is_bool($index) || (string) (int) $index === (string) $index) { //this is line 457
        return (int) $index;
    }

    return (string) $index;
}

the error is generated after calling the $form->bind($request) method;

   if ($request->isMethod('POST')) {

        $form->bind($request);
        $searchQuery = $form->getData();
    }

Upvotes: 0

Views: 3527

Answers (1)

redbirdo
redbirdo

Reputation: 4957

When bind() tries to map your data values to the form, it's getting an array value for a Choice field where it's expecting a single string value.

It may be that the Choice field should allow multi-select, in which case you need to make sure that when you create the Choice control you set 'multiple' to true (and also consider the 'expanded' option).

Otherwise, it's not possible to diagnose your issue unless you post the code that creates the form and the class or data structure that maps onto the form.

Upvotes: 1

Related Questions