PHP / Symfony2表单复选框字段 [英] PHP/Symfony2 Form Checkbox field

查看:190
本文介绍了PHP / Symfony2表单复选框字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Orm

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

        // ...

        motion:
            type: smallint
            unsigned: true

/ p>

Type

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

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

    // ...
}

p>

Error


给定类型Boolean,integer的预期参数

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






我想通过复选框打开和关闭。
该值由0和1分配。

即使它给出了value参数也是无用的。


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
));

我应该怎么办?

推荐答案

在您的ORM映射定义中,您必须将 motion 定义为布尔值,而不是smallint。和FYI,Symfony将TINYINT解释为布尔值和任何其他整数SQL类型作为整数。

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

这篇关于PHP / Symfony2表单复选框字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆