[TYPO3-mvc] Optional \DateTime Property
Werner Stotter
typo3 at itfix.at
Thu Oct 23 13:27:58 CEST 2014
Hi,
one way is to manage this within your model:
/**
* dateOfBirth
*
* @var \DateTime
*/
protected $dateOfBirth = NULL;
and use this setter:
/**
* Sets the dateOfBirth
*
* @param \DateTime $dateOfBirth
* @return void
*/
public function setDateOfBirth(\DateTime $dateOfBirth=NULL) {
if ($dateOfBirth) $this->dateOfBirth = $dateOfBirth;
}
hope this helps.
greets
Am 23.10.2014 13:04, schrieb Philipp Wrann:
> Hey
>
> How can i set a Property of type \DateTime optional?
> I allways get a validation error because the property should be
> \DateTime but is NULL
>
> I solved it that way:
> if ($this->request->hasArgument('groupRequest')) {
> $request = $this->request->getArgument('groupRequest');
> if (strlen($request['alternateArrival'])) {
>
> $mappingConfiguration->forProperty('alternateArrival')->setTypeConverterOption(
>
>
> 'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
>
> \TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,
>
> $this->settings['dateFormat']
> );
> } else {
>
> $mappingConfiguration->skipProperties('alternateArrival');
> }
> if (strlen($request['alternateDeparture'])) {
>
> $mappingConfiguration->forProperty('alternateDeparture')->setTypeConverterOption(
>
>
> 'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
>
> \TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,
>
> $this->settings['dateFormat']
> );
> } else {
>
> $mappingConfiguration->skipProperties('alternateDeparture');
> }
> }
>
> Can i set @optional or something in the property?
> cant find documentations on this
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>
>
More information about the TYPO3-project-typo3v4mvc
mailing list