0
votes

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();
    }
1
what that if statement should do? - DonCallisto
I did not understand ! - bili
Could you explain to me what that "if" will do, to you? - DonCallisto
I think this may have something to do with your entiy class that is passed into the form, it is a little difficult to help you debug this with little information. Can you post the Entity, the form class, and that part of the controller along with the symfony version as the syntax changes slightly per release and would hate to give you incorrect syntax - Matthew A Thomas

1 Answers

1
votes

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.