0

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();
    }
4
  • 1
    what that if statement should do? Commented Sep 26, 2014 at 8:26
  • I did not understand ! Commented Sep 26, 2014 at 8:55
  • 1
    Could you explain to me what that "if" will do, to you? Commented Sep 26, 2014 at 9:06
  • 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 Commented Sep 26, 2014 at 10:38

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.