6

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?

1 Answer 1

10

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. You sure made things easy for me.

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.