Checkbox 设置默认值';选定的';在zend 2表单的复选框元素中

Checkbox 设置默认值';选定的';在zend 2表单的复选框元素中,checkbox,zend-framework2,zend-form,Checkbox,Zend Framework2,Zend Form,我想在zend 2中为我的复选框设置一个默认的“选中的” 我尝试添加默认值 '值'=>'选定' 但它似乎不起作用 $this->add(array( 'type' => 'Zend\Form\Element\Checkbox', 'name' => 'receiveNewsletters', 'options' => array( 'value_options' =&g

我想在zend 2中为我的复选框设置一个默认的“选中的”

我尝试添加默认值

'值'=>'选定'

但它似乎不起作用

$this->add(array(
            'type' => 'Zend\Form\Element\Checkbox',
            'name' => 'receiveNewsletters',
            'options' => array(
                'value_options' => array(
                    '1' => 'Untick if you do not want to receive promotional emails',
                ),
                'attributes' => array(
                    'value'=>'selected',
                ),
            ),    

        ));

该值应为选中的
。默认情况下,它是
'1'

$this->add(array(
    'type' => 'Zend\Form\Element\Checkbox',
    'name' => 'receiveNewsletters',
    'options' => array(
        'label' => 'Untick if you do not want to receive promotional emails',
    ),
    'attributes' => array(
        'value' => '1',
    ),
));

我在这段代码中没有看到任何
选中的值
,Hi Gennadiy,它不起作用。我试过你的代码,但没有work@GennadiyLitvinyuk嘿,Gennadiy。非常感谢你。现在可以了。