我正在使用cake 2.0.6并且我试图保存多个记录,这些记录是我从表单输出数据的产品;
我不能保存两个记录,我的表格中的字段设置为; 0是它应该保存的第一条记录。由于某种原因,它不会保存2条记录。我已经关闭了产品型号的所有验证,并且没有presave方法
任何想法都错了吗?
<input name="data[Product][0][product_code]"/>
<input name="data[Product][0][colour]"/>
<input name="data[Product][0][lead_time_weeks]"/>
<input name="data[Product][0][description]"/>
<input name="data[Product][0][height]" />
<input name="data[Product][0][width]" />
<input name="data[Product][0][depth]" />
<input name="data[Product][0][price]" />
<input name="data[Product][0][discount]" />
<input name="data[Product][0][discounted_price]" />
<input name="data[Product][0][quantity]"/>
<input name="data[Product][1][product_code]"/>
<input name="data[Product][1][colour]"/>
<input name="data[Product][1][lead_time_weeks]"/>
<input name="data[Product][1][description]"/>
<input name="data[Product][1][height]" />
<input name="data[Product][1][width]" />
<input name="data[Product][1][depth]" />
<input name="data[Product][1][price]" />
<input name="data[Product][1][discount]" />
<input name="data[Product][1][discounted_price]" />
<input name="data[Product][1][quantity]"/>
Array
(
[Product] => Array
(
[0] => Array
(
[product_code] => fgfgf
[colour] =>
[lead_time_weeks] =>
[description] =>
[height] => 11111
[width] => 22222
[depth] =>
[price] =>
[discount] => 50
[discounted_price] =>
[quantity] =>
)
[1] => Array
(
[product_code] => fgfgf
[colour] =>
[lead_time_weeks] =>
[description] =>
[height] => 123
[width] => 123
[depth] =>
[price] =>
[discount] => 50
[discounted_price] =>
[quantity] =>
)
)
)
编辑:解决方案供将来参考;像这样调用save方法;
$这 - >制品 - >白水回收($这 - >请求 - >数据[ '产品']
你怎么称呼saveAll
?常见的错误是称之为
$this->Product->saveAll($data);
当你应该这样做的时候
$this->Product->saveAll($data['Product']);
必须在没有Model键的情况下对其进行数字索引
根据文档:https://book.cakephp.org/2.0/en/models/saving-your-data.html
请注意,我们传递$ data ['Article']而不是通常的$ data。保存同一模型的多个记录时,记录数组应该只是在没有模型键的情况下进行数字索引。