在获取$selected
变量中的值时,我必须显示复选框。当前在以下情况下,我必须显示两个复选框为选中状态,但是我的代码无法正常工作。我该如何解决?
$checkboxarray = [
'0' => "By Value",
'1' => "By Quantity",
'2' => "By Date"
];
$selected = explode(",", "0,1");
echo $this->Form->select('mo_type', $checkboxarray, array( 'selected' => $selected, 'multiple' => 'checkbox'));
答案 0 :(得分:0)
您可以尝试使用默认而不是 selected 属性
$checkboxarray = [
'0' => "By Value",
'1' => "By Quantity",
'2' => "By Date"
];
$selected = explode(",", "0,1");
echo $this->Form->select('mo_type', $checkboxarray, array( 'default' => $selected, 'multiple' => 'checkbox'));
正确的方法是使用“ val ”属性
echo $this->Form->select('mo_type', $checkboxarray, array( 'val' => $selected, 'multiple' => 'checkbox'));