[TYPO3-mvc] Copy object and add to repository
Franz Koch
typo3.RemoveForMessage at elements-net.de
Wed Apr 6 15:53:55 CEST 2011
Hey,
> I try to copy an object and add it to the database:
>
> ------------------
> // Change product title
> $product->setProductName('[Copy of] ' . $product->getProductName());
>
> $this->productsRepository->add($product);
$newProduct = clone($product);
$newProduct->setProductName('[Copy of] ' . $product->getProductName());
$this->productsRepository->add($newProduct);
That should do the trick. The magic lies in "clone" which is creating a
new "identity".
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list