如何设置Zend_Form无线电元素的默认选中值?

And*_*rew 4 zend-framework zend-form

我有一个有两个选项的无线电元素.我想将一个设置为默认值,以防用户忘记检查它.我怎样才能做到这一点?

解:

$this->addElement('radio', 'choose', array(
    'required'   => true,
    'multiOptions' => array(
        'yes' => 'heck yes',
        'no' => 'please no'
    ),
    'value' => 'yes' //key of multiOption
));
Run Code Online (Sandbox Code Playgroud)

tim*_*one 7

使用带键的setValue.例如:

$enablestate=new Zend_Form_Element_Radio('enablestate');
$enablestate->addMultiOptions(array('enabled'=>'Enabled','unenabled'=>'Unenabled'));
$enablestate->setSeparator('')->setValue('enabled');
Run Code Online (Sandbox Code Playgroud)