我正在制作一个编辑表单,其中应根据数据库记录选择单选按钮字段。现在如何编写代码
<?php
$gender=$employee['EmployeePersonal']['gender'];
$options2= array(
'male' => 'Male',
'female' => 'Female',
);
$attributes2 = array(
'legend' => false,
'checked' =>$gender,
);
echo $this->Form->radio('EmployeePersonal.type', $options2, $attributes2); ?>
答案 0 :(得分:4)
只需将选项“值”设置为所需的值
即可$gender=$employee['EmployeePersonal']['gender'];
$options2= array(
'male' => 'Male',
'female' => 'Female',
);
$attributes2 = array(
'legend' => false,
'value' => $gender,
);
echo $this->Form->radio('EmployeePersonal.type', $options2, $attributes2);
了解更多信息FormHelper::radio
希望这会对你有所帮助。
答案 1 :(得分:1)
尝试使用自动填充的“男性”值
<?php echo $this->Form->radio('gender', array(
'Male' => 'Male',
'Female' => 'Female',
),
array(
'legend' => false,
'value' => 'Male',
)
);?>