繁体   English   中英

PHP / Symfony2表单复选框字段

[英]PHP/Symfony2 Form Checkbox field

奥姆

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分配。
即使它给出了value参数也没用。

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

我应该怎么做?

在ORM映射定义中,您必须将motion定义为布尔值而不是smallint。 而且,仅供参考,Symfony将TINYINT解释为布尔值,将任何其他整数SQL类型解释为整数。

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

        // ...

        motion:
            type: boolean

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM