Reputation: 1531
I have cloned/saved a copy of an SQL record using CakePhp like so:
$contract = $this->Contract->findById($id);
$contract['Contract']['id'] = NULL;
$this->Contract->save($contract); // And save it
I want to be able to redirect the user to the 'Edit' view of the cloned record after the clone is complete. Basically, I need to do something like this:
$this->redirect(array('controller' => 'contracts', 'action' => 'edit', $cloneId));
My question is, how do I get the ID of the clone immediately after saving the new record?
Upvotes: 0
Views: 972
Reputation: 4177
you can also get the last inserted record id in these ways.
$cloneId = $this->Contract->id;
or
$cloneId = $this->Contract->getLastInsertID();
or
$contract = $this->Contract->save($contract);
$cloneId = $contract['Contract']['id']
Upvotes: 3