问题
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