echo $this->Form->input('product_id', array(
'label'=>false,
'type'=>'select',
'multiple'=>'checkbox',
'options'=>$product,
));
我正在尝试添加' checked => true'从输入但失败
这是表单编辑的屏幕截图,未选中已选中的数据
答案 0 :(得分:0)
你可以告诉CakePHP通过传递selected
值数组来检查哪些复选框: -
$selected = []; // An array of selected values
echo $this->Form->input('product_id', array(
'label' => false,
'type' => 'select',
'multiple' => 'checkbox',
'options' => $product,
'selected' => $selected
));
如果您想要选择所有值,可以将$product
的数组键传递给selected
选项: -
$selected = array_keys($product);
echo $this->Form->input('product_id', array(
'label' => false,
'type' => 'select',
'multiple' => 'checkbox',
'options' => $product,
'selected' => $selected
));