Im using cake 2.0.6 and im trying to save multiple records that are products my data output from the form is below;
I cant get it to save the two records, the fields in my form are set like; with 0 being the first record it should save. It wont save the 2 records for some reason. Ive turned off all validation for the product model and have no beforesave method
Any ideas whats wrong?
<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] =>
)
)
)
EDIT:
Solution for future reference;
Call the save method like this;
$this->Product->saveAll($this->request->data[‘Product’]
How do you call
saveAll? The common mistake is to call it likeWhen you should have done it like
It has to be numerically indexed without the Model key
As per the docs:
https://book.cakephp.org/2.0/en/models/saving-your-data.html