1

I would like to record a choice of checkboxes in my data base. I get this error:

ContextErrorException: Notice: Array to string conversion in //vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php line 120

My form :

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('adult_available', 'choice', array(
            'choices'   => array('A' => 'Adult', 'C' => 'Children'),
            'required'  => false,
            'expanded' => true,
            'multiple' => true
        ));

My field :

/**
     * @ORM\Column(type="string", columnDefinition="CHAR(1) NOT NULL")
     */
    protected $adult_available;

My form looks good! But when I submit I got the ContextErrorException exception

Thanks!

4
  • That field holds a single value, but you have allowed the form to expect multiple values. Commented Jan 20, 2014 at 16:19
  • You say that is my field is wrong : @ORM\Column(type="string", columnDefinition="CHAR(1) NOT NULL") ? Commented Jan 21, 2014 at 10:16
  • I don't know whether the field should be a collection, or if the form should only return a single value on submit. I only know that at the moment it looks like they contradict each other. Commented Jan 21, 2014 at 10:20
  • Thanks. I'm very new with symfony and doctrine. I would like to store in database a multiple choice (with chexboxes) but without create a new entity. Is it possible? Commented Jan 21, 2014 at 10:40

1 Answer 1

1

Try this:

/**
 * @var array
 *
 * @ORM\Column(name="adult_available", type="simple_array")
 */
private $adultAvailable;
Sign up to request clarification or add additional context in comments.

1 Comment

@user2775846 tick me then! :)

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.