Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP/Symfony2 Form Checkbox field

Orm

My\SampleBundle\Entity\Subject:
    type: entity
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:

        // ...

        motion:
            type: smallint
            unsigned: true

Type

public function buildForm(FormBuilderInterface $builder, array $options)
{
    // ...

    $builder->add('motion', 'checkbox', array(
        'required'  => false
    ));

    // ...
}

Error

Expected argument of type "Boolean", "integer" given


I would like to turn on and off by a check box. The value is distributed by 0 and 1.
It was useless even if it gave the value parameter.

$builder->add('motion', 'checkbox', array(
    'value'     => 1,
    'required'  => false
));

How should I do?

like image 774
R.Atim Avatar asked Dec 10 '12 12:12

R.Atim


1 Answers

In your ORM mapping definition, you have to define motion as a boolean instead of a smallint. And FYI, Symfony interprets TINYINT as boolean and any other integer SQL types as integers.

My\SampleBundle\Entity\Subject:
    type: entity
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:

        // ...

        motion:
            type: boolean
like image 184
AlterPHP Avatar answered Sep 28 '22 17:09

AlterPHP