I read Convert multiple records . Now I am trying to save several photos from the form at once.
WITH
debug($this->request->data);
I have it:
[ (int) 1 => [ 'filename' => '25483_106728809362869_5795827_n.jpg', 'description' => '', 'album_id' => '2' ], (int) 3 => [ 'filename' => '44569_193398817463220_816845208_n.jpg', 'description' => '', 'album_id' => '1' ] ]
Seems good.
Bake created this action method for me:
public function add() { $photo = $this->Photos->newEntity(); if($this->request->is('post')) { $photo = $this->Photos->patchEntity($photo, $this->request->data); if($this->Photos->save($photo)) { return $this->redirect(['action' => 'index']); } } $this->set(compact('photo')); }
But CakeBook does not explain how to proceed. I feel like I need to use newEntities() and patchEntities() , but I don't quite understand how to do this.
For example: why can the newEntity() method accept NULL, and newEntities() method necessarily want an argument? Does the save() method accept only one entity at a time? So, do I need to save the save cyclically for each object?
Can I take a small example? Thanks.
source share