【发布时间】:2017-04-25 06:51:40
【问题描述】:
我已将数据存储在两个表中的多选选项中。
表格: 用户:
id user_name status
1 test 1
2 test2 1
3 test3 1
4 test4 1
爱好:
id hobby_name
1 Cricket
2 Movie
3 Football
4 Music
5 Dance
我保存了如下数据:
id user_id hobby_id
1 1 5
2 1 19
3 2 17
4 2 18
每个用户都有多个爱好。现在,当我编辑 user_id 1 时,我想在多个选择框中显示选定的 ID。
我在UsersCroller.php 中提取了hobbies 数据,如下所示:
$this->loadModel('Hobby');
$hobbies = $this->Hobby->find('list', array('fields' => array('Hobby.id', 'Hobby.hobbyname'), 'recursive' => -1));
$this->set(compact('hobbies'));
在admin_add.ctp 中创建了下拉选择框,如下所示:
<?php echo $this->Form->input('hobbies', array("label" => false, 'multiple' => 'multiple', 'type' => 'select', 'options' => $hobbies, "empty"=>"Select Hobbies", "div" => false, "class" => "m-wrap span12 validate[required]", "data-errormessage-value-missing" => "Please select the hobbies!" )); ?>
当我编辑和显示多选时如何获取这些记录。
【问题讨论】:
-
你能在这里显示复选框吗?
-
你试过'multiple' => true
-
是的,我试过
'multiple' => true。 -
user_ids 是如何编辑的?我只是想弄清楚编辑用户 ID 和显示所选 ID 之间的关系是什么 -
你在'options'中传递数组吗 => $options, 'selected' => $selected 这样
标签: php mysql cakephp cakephp-2.0 multiple-tables