php - How to save multiple records in cakephp 3.4.12 -
i trying save multiple records in single table. facing problem while saving form data. problem might form elements. please me on issue
controller save method
$data = $this->request->data(); $stockin = tableregistry::get('stockin'); $entities= $stockin->newentities($data); $stockin->savemany($entities);
form
echo $this->form->input("stockin.$i.date", [ 'value' => $stockindate]); echo $this->form->input("stockin.$i.product_id", [ 'value' => $prod->id]); echo $this->form->input("stockin.$i.quantity", ['label' => false] ); echo $this->form->input("stockin.$i.harvested", ['options' => $harvested,'label' => false]); echo $this->form->input("stockin.$i.price", [ 'label' => false]);
post array value
[ 'stockin' => [ (int) 0 => [ 'date' => '2017-08-18', 'product_id' => '3', 'quantity' => '1', 'harvested' => 'k', 'price' => '1212' ], (int) 1 => [ 'date' => '2017-08-18', 'product_id' => '2', 'quantity' => '2112', 'harvested' => 'k', 'price' => '12312' ], (int) 2 => [ 'date' => '2017-08-18', 'product_id' => '1', 'quantity' => '12', 'harvested' => 'k', 'price' => '12' ] ]
]
instead of $data
, need mention $data['stockin']
$data = $this->request->data(); $stockin = tableregistry::get('stockin'); $entities = $stockin->newentities($data['stockin']); // modify line $stockin->savemany($entities);
Comments
Post a Comment