0

当我获取$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'));
4

1 回答 1

0

您可以尝试使用默认属性而不是选定属性,

$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'));
于 2018-07-26T14:27:37.283 回答