加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP / Symfony2表单复选框字段

发布时间:2020-12-13 14:10:16 所属栏目:PHP教程 来源:网络整理
导读:奥姆 MySampleBundleEntitySubject: type: entity id: id: type: integer generator: { strategy: AUTO } fields: // ... motion: type: smallint unsigned: true 类型 public function buildForm(FormBuilderInterface $builder,array $options){ // ...
奥姆
MySampleBundleEntitySubject:
    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
    ));

    // ...
}

错误

Expected argument of type “Boolean”,“integer” given

我想通过复选框打开和关闭.
该值由0和1分配.
即使它给出了value参数也没用.

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

我应该怎么做?

在ORM映射定义中,您必须将motion定义为布尔值而不是smallint.而且,仅供参考,Symfony将TINYINT解释为布尔值,将任何其他整数SQL类型解释为整数.
MySampleBundleEntitySubject:
    type: entity
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:

        // ...

        motion:
            type: boolean

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读