我在两个表之间有一个HABTM关系:items
和locations
,使用表items_locations
加入它们。CakePHP一次编辑多条记录
items_locations
也存储更多信息。这里的架构
items_locations(id, location_id, item_id, quantity)
我想马上建立一个网页,其中显示了一个位置的所有项目,并让用户通过一个DataGrid风格界面,编辑多个领域:
Location: Factory XYZ
___________________________
|___Item____|___Quantity___|
| Widget | 3 |
| Sprocket | 1 |
| Doohickey | 15 |
----------------------------
为了解决这个问题,我有一个名为InventoryController
控制器,它具有:
var $uses = array('Item', 'Location'); // should I add 'ItemsLocation' ?
如何构建多维形式来编辑这些数据?
编辑:
我试图让我的数据看起来像Deceze如何下面描述,但我又遇到了问题......
// inventory_controller.php
function edit($locationId) {
$this->data = $this->Item->ItemsLocation->find(
'all',
array(
"conditions" => array("location_id" => $locationId)
)
);
当我这样做,$this->data
出来是这样的:
Array (
[0] => Array (
[ItemsLocation] => Array (
[id] => 16
[location_id] => 1
[item_id] => 1
[quantity] => 5
)
)
[1] => Array (
[ItemsLocation] => Array (/* .. etc .. */)
)
)
现在有更多的意义..虽然我仍然打砖墙。介意看看我编辑原始帖子? – nickf 2009-09-04 04:23:53
那么,当你找到**数据时,格式会稍有不同。我在说的是**将表单发布到控制器的正确格式**在接收到POST数据后,在控制器中尝试一个'debug($ this-> data)'。 – deceze 2009-09-04 05:15:19
但是你不需要这种格式的视图能够做一些类似于:'$ form-> input('ItemsLocation.0.id')' – nickf 2009-09-04 05:51:39