How to clone/copy a sql record with CakePhp? Is there a native way or do I need to find my record and then save it?
You need to use the find and save function.
$record = $this->Model->findById(1);
$record['Model']['id'] = NULL;
$this->Model->save($record);
There is no native "copy" command by itself. But a find/read operation followed by a create/save should work.
$row = $this->Model->findById(1);
$this->Model->create(); // Create a new record
$this->Model->save($row); // And save it
Would copy the row with id 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With