CakePHP 2.0选择多个表单

问题描述 投票:4回答:1

我有这个下拉菜单,您可以在其中选择多个值。现在,假设我要编辑我的信息并使用多个选定值创建一个下拉菜单。试图弄清楚进展如何,但没有结果。

假设我有:

$selected = array(3, 4);
$options = array(1,2,3,4);

echo $this->Form->select('Attendees', $options,array('multiple' => true, 'selected' => $selected));

我已使用此代码,但未选择任何内容。

php cakephp-2.0 selected form-helpers
1个回答
6
投票

确定了一种方法,显然它需要像这样:

$selected = array(2, 3);
$options = array(1, 2, 3, 4);

echo $this->Form->input('Attendees', array('multiple' => true, 'options' => $options, 'selected' => $selected));

将输出:

  • 1
  • 2
  • 3选中
  • 4个已选中

$ selected检查每个元素的索引键而不是值本身。

© www.soinside.com 2019 - 2024. All rights reserved.