[TYPO3-mvc] Cloning Model and add to repository
Manfred Rutschmann
manfred.rutschmann at revier.de
Tue Jun 15 07:57:30 CEST 2010
Am Mon, 14 Jun 2010 15:11:04 +0200 schrieb Sebastian Kurfürst:
> $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);
Hey Sebastian,
i tried out your workaraound and get a strange error in the extbase mapper
class:
Fatal error: Call to a member function getClassSchema() on a non-object in
C:\xampp170\htdocs\xxx\typo3\sysext\extbase\Classes\Property\Mapper.php on
line 180
Commented out the line 180
// $targetClassSchema =
$this->reflectionService->getClassSchema(get_class($target));
and the new object can stored successfull in the database with this code:
// create a new empty object
$newlabel = new Tx_MrEtikett_Domain_Model_Label();
// instance the property mapper
$propertyMapper = t3lib_div::makeInstance('Tx_Extbase_Property_Mapper'); //
Singleton
// map the source to target
$propertyMapper->map(
array( // Property list
'title',
'theme',
'description',
'config',
'image'
),
$label, // source object
$newlabel // target object
);
$newlabel->title = $newlabel->title.' (Kopie)'; // set new title
// copy the labelfiles in new ones
$newlabel = $this->helper->copyLabelFile($newlabel, $label->image);
// add to reposotory
$this->labelRepository->add($newlabel);
// Add a flash message
$this->flashMessages->add('Etikett wurde kopiert.');
// Redirect to index
$this->redirect('index');
Best wishes
Manfred
More information about the TYPO3-project-typo3v4mvc
mailing list