I want to save 10 times in Cakephp using Save function with for loop but it doesn’t seem to work. It only saves one data.
How can we make it so it saves multiple data at one call?
Below is my code…
for($i=0;$i<10;$i++){
$unique_id = $this->_unique($userData['User']['id']); // Unique id with userid as initial prefix
$this->data['Invite'] = array('invited_user' => $userData['User']['id'], 'unique_id' => $unique_id);
$this->User->Invite->save($this->data['Invite']);
}
You need to call Model::create( ) for each iteration of the loop. IE: