Sonata Admin: Boolean selectbox for boolean properties

余生长醉 提交于 2019-12-13 02:24:10

问题


I have defined a boolean property in my Entity:

    /**
     * @var boolean
     * @Assert\Type(type="bool")
     * @ORM\Column(name="is_managed", type="boolean", nullable=true, options={"default": true})
     */
    protected $isManaged = true;

When I use it in the sonata admin bundle it just generates an select box with values "1" and "2" - I expected "true" or "false" selection.

$datagridMapper
      ->add('description')
      ->add('isManaged', 'doctrine_orm_boolean')

generates the code:

<select id="filter_isManaged_value" name="filter[isManaged][value]" class="form-control select2-offscreen" tabindex="-1" title="Is Managed"><option value=""></option>            <option value="label_type_yes">1</option>            <option value="label_type_no">2</option></select>

Can somebody help me?


回答1:


Try this:

            ->add('isManaged', null, array(
                'label' => 'Is Managed',
                    ), 'sonata_type_translatable_choice', array(
                'translation_domain' => "SonataAdminBundle",
                'choices' => array(
                    1 => 'label_type_yes', // or 'True'
                    2 => 'label_type_no' // or 'False'
                ))
            )

Documentation



来源:https://stackoverflow.com/questions/37862446/sonata-admin-boolean-selectbox-for-boolean-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!