1

假设我有一个模型 A 和 B 以及 A hasMany B。我想制作一个表单以允许用户添加模型 A 的实例,同时还能够添加模型 B 的尽可能多的(关联)实例。

但是,使用表单助手在表单中执行类似echo $this->Form->input('A.B.some_field')操作并没有达到预期的效果。正确执行此操作的最佳方法是什么?

4

1 回答 1

2

关键是要有与find('all')/格式匹配的表单数据saveAll($data)

您需要以下内容:

echo $this->Form->create('A');
echo $this->Form->input('A.id');

echo $this->Form->input('B.0.some_field');
echo $this->Form->input('B.1.some_field');
...

echo $this->Form->submit();
echo $this->Form->end();

这将生成与 saveAll 期望的格式相同的数据

于 2013-07-18T22:07:09.543 回答