I am using two models 'User' and 'UserImage'.. Where in i am going to save multiple rows into user_images table.. The view for UserImage is below..
echo $this->Form->input('UserImage.0.photo');
echo $this->Form->input('UserImage.1.photo');
echo $this->Form->input('user_id');
echo $this->Form->end(__('Submit'));
Then how to save multiple rows..
From the doc of cakephp 2.x:
For saving multiple records of single model, $data needs to be a numerically indexed array of records like this:
Note that we are passing numerical indexes instead of usual $data containing the Article key. When saving multiple records of same model the records arrays should be just numerically indexed without the model key.
It is also acceptable to have the data in the following format:
I have tried the first one and it worked great.
HTH.
you could use this one saveMany() to insert each image as new record. I used same to solve my problem. Every thing looks alright in paul.ago 's answer but just change saveAll() to saveMany()
You should specify the model of each field if you have more models involved. Also, you need to specify for each record the related field (user_id).
Try this:
Plus use this to save multiple records and multiple models:
See document of cakephp there is a method say saveAll() Cake PHP Saving Your Data