如何创建两个单选按钮,根据$foo的值预先选择一个?下面的代码段创建它们,但不能选择两个按钮之一.
$options = array('standard' => ' Standard','pro' => ' Pro'); $attributes = array( 'legend' => false,'value' => false,'checked'=> ($foo == "pro") ? FALSE : TRUE,); echo $this->Form->radio('type',$options,$attributes);
这很简单..使用默认值$foo:
$options = array( 'standard' => 'Standard','pro' => 'Pro' ); $attributes = array( 'legend' => false,'value' => $foo ); echo $this->Form->radio('type',$attributes);
您可以在文档中看到:
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::radio