CakePHP创建单选按钮

ste*_*tef 9 cakephp

如何创建两个单选按钮,其中一个是基于$ 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);
Run Code Online (Sandbox Code Playgroud)

Thi*_*lem 27

这很简单..使用$ foo的默认值:

$options = array(
    'standard' => 'Standard',
    'pro' => 'Pro'
);

$attributes = array(
    'legend' => false,
    'value' => $foo
);

echo $this->Form->radio('type', $options, $attributes);
Run Code Online (Sandbox Code Playgroud)

正如您在文档中看到的那样:

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::radio