cakephp:如何显示从编辑中选择的复选框值

时间:2017-07-13 04:01:14

标签: cakephp cakephp-2.0 cakephp-2.1

echo $this->Form->input('product_id', array(
                                                'label'=>false,
                                                'type'=>'select',
                                                'multiple'=>'checkbox',
                                                'options'=>$product,


                                            )); 

我正在尝试添加' checked => true'从输入但失败

this is screenshoot of the form edit, the data already selected is not checked

这是表单编辑的屏幕截图,未选中已选中的数据

1 个答案:

答案 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
));