CakePHP 2.0选择表格多个选择 [英] CakePHP 2.0 Select form Multiple selected

查看:115
本文介绍了CakePHP 2.0选择表格多个选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have have this dropdown menu where you can select multiple values. Now let's say I want to edit my info and make a dropdown menu with multiple selected values. Trying to figure out how it goes, but no results.

假设我有:

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

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

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

I've used this code, but nothing is selected.

推荐答案

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

Ok found a way, appearantly it needs to be like this:

$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检查每个元素的索引键,而不是值本身.

The $selected checks the index key of each element rather the value itself.

这篇关于CakePHP 2.0选择表格多个选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆