对不起,我到处看了。当然,我在使用数组的 PHP 中犯了一个基本错误。仅当我使用参数 'selected' => array (1,45,46) 时,FormHelper 才会返回正确的 HTML 输入复选框。当他们尝试使用从控制器发送的数组时,无法正确显示。如何将数组转换为在参数“选定”中工作。我究竟做错了什么。
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)));