对不起,我到处都是。当然,我在PHP中使用数组做了一个基本错误。仅当我使用参数'selected'=>时,FormHelper才会返回正确的HTML输入复选框。阵列(1,45,46)。当他们尝试使用从控制器发送的数组时,无法正常显示。如何将数组转换为参数“selected”。我做错了什么。
debug($selected_dostrony);
/*
array(
(int) 0 => '1',
(int) 1 => '45',
(int) 2 => '39',
(int) 3 => '46',
(int) 4 => '40',
(int) 5 => '41',
(int) 6 => '42',
(int) 7 => '43',
(int) 8 => '44'
)
*/
$selected_dostrony=implode(", ", $selected_dopostu);
debug($selected_dostrony);
/*
'1, 45, 39, 46, 40, 41, 42, 43, 44'
* /
echo $this->Form->input('Product', array('multiple' => 'checkbox', 'options' => $dopostu, 'selected' => $selected_dopostu));
echo $this->Form->input('Product', array('multiple' => 'checkbox', 'options' => $dopostu, 'selected' => $selected_dostrony));
/* this works */
echo $this->Form->input('Product', array('multiple' => 'checkbox', 'options' => $dopostu, 'selected' => array(1,45,46)));