2017-07-13 88 views
2
echo $this->Form->input('product_id', array(
               'label'=>false, 
               'type'=>'select', 
               'multiple'=>'checkbox', 
               'options'=>$product, 


              )); 

我试图将选中该复选框值“检查=>真正的”从输入,但未能CakePHP的:如何显示已经从编辑

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

这是screenshoot表格编辑,已经选择的数据不检查

回答

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 
)); 
+0

如果已选择或已保存的,那么如何显示的数据?,因为表单添加已被选中,那么现在问题出现在表单编辑上 – zen