[Flow] \DateTimeConverter

Bastian Waidelich bastian at typo3.org
Mon Jun 3 14:40:59 CEST 2013


mario chiari wrote:

Hi Mario,

> I have a Father/Son situations
> [...] to define multiple Father, each with multiple Sons.

I just had to think about how much more complicated life would be if 
family members had MM-relations :)



> Hence, my createAction() needs to be defined something like:
>
> public function createAction(array $newFather) {
>        $propertyMapper = new \TYPO3\Flow\Property\PropertyMapper();
>        foreach($newFather as $id => $father){
>        $fatherObj = $propertyMapper->convert($father,'\...\Model
> \Father');
>       $this->fatherRepository->add($fatherObj);

> }

PropertyMapper::convert() expects a third parameter $configuration.
You should be able to use that "manually":


$propertyMappingConfiguration = new 
\TYPO3\Flow\Property\PropertyMappingConfiguration();
$propertyMappingConfiguration->forProperty('my_date')
	->setTypeConverterOption('TYPO3\Flow\Property\TypeConverter
                \DateTimeConverter', \TYPO3\Flow\Property\TypeConverter
                \DateTimeConverter::CONFIGURATION_DATE_FORMAT,'Y-m-d');}

$fatherObj = $propertyMapper->convert($father,'\...\Model
\Father', $propertyMappingConfiguration);


But why do you go for an array in the first place?

If your action looked like this:

public function createAction(\...\Model\Father $newFather) {
}

you wouldn't have to interact with the property mapper directly in the 
first place..


HTH

-- 
Bastian Waidelich
--
Core Developer Team

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the Flow mailing list