[TYPO3-mvc] Cloning Model and add to repository
Sebastian Kurfürst
sebastian at typo3.org
Mon Jun 14 15:11:04 CEST 2010
Hey,
please try using the property mapper to create a "cloned" instance of an
object.
So, I'd try as follows:
$oldObject = ...
$newObject = new Tx_My_Object();
$propertyMapper = t3lib
_div::makeInstance('Tx_Extbase_Property_Mapper'); // Singleton
$propertyMapper->map(array('property1', 'property2'), $oldObject,
$newObject);
$this->myRepository->add($newObject);
Greets,
Sebastian
Am 14.06.10 13:10, schrieb Manfred Rutschmann:
> Am Sun, 13 Jun 2010 17:48:43 +0200 schrieb Thomas "Thasmo" Deinhamer:
>
>>
>> Not sure, but maybe just the error message is not correct.
>> Maybe you can use somethinkg like $repository->update($newlabel).
>>
>> Thomas
>
> Nothing happened....
>
> Way one: Put a object to my copy controller an make this:
>
> public function copyAction(Tx_MrEtikett_Domain_Model_Label $label) {
> $newlabel = new Tx_MrEtikett_Domain_Model_Label;
> $newlabel = clone $label;
> $this->labelRepository->add($newlabel);
> }
>
> I get this error an a brand new uid:
> #1222871239: The uid "61" has been modified, that is simply too much.
>
> I think the problem is, in my object is in [uid:protected]=> 59 in the
> [_cleanProperties:private] array.
>
> Way two:
> Using repository->update nothing happens, i think the original object is
> updated in the db.
>
> How clone objects and store as new one in the database?
>
> Manfred
More information about the TYPO3-project-typo3v4mvc
mailing list