PHP/Symfony2 表单复选框字段

6

Orm

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

        // ...

        motion:
            type: smallint
            unsigned: true

类型

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

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

    // ...
}

错误

预期的参数类型为“布尔值”,但给定了“整数”


我想通过复选框来打开和关闭。 该值分配为0和1。
即使给定了值参数也是无用的。

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

How should I do?

1个回答

10
在您的ORM映射定义中,您需要将motion定义为布尔值,而不是小整数。另外,FYI,Symfony将TINYINT解释为布尔值,将其他整数SQL类型解释为整数。

在您的ORM映射定义中,您需要将motion定义为布尔值,而不是小整数。另外,FYI,Symfony将TINYINT解释为布尔值,将其他整数SQL类型解释为整数。

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

        // ...

        motion:
            type: boolean

1
谢谢。你确实让我的工作变得轻松了。 - R.Atim

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接