[Flow] Optional DateTimeConverter
Jan Greth
jan at greth.me
Sun Oct 5 16:59:27 CEST 2014
Hey again!
In my Model i have a \DateTime property, which is optional:
---------------------------------------------
[...]
/**
* @var \DateTime
* @ORM\Column(nullable=true)
*/
protected $stopdate;
[...]
/**
* Constructs this item
*/
public function __construct() {
[...]
$this->stopdate = NULL;
}
[...]
---------------------------------------------
In my controller i have a initializeUpdateAction for Type converting.
---------------------------------------------
public function initializeUpdateAction() {
[...]
$this->arguments['item']->getPropertyMappingConfiguration()
->forProperty('stopdate')->setTypeConverterOption(
TYPO3\Flow\Property\TypeConverter\DateTimeConverter',
\TYPO3\Flow\Property\TypeConverter
\DateTimeConverter::CONFIGURATION_DATE_FORMAT,
'm/d/Y H:i');
[...]
}
---------------------------------------------
But, as my property is optional, i can submit it empty (null) and doing
this brings me the exception:
---------------------------------------------
#1297759968: Exception while property mapping for target type
"Vendor\Package\Domain\Model\Item", at property path "": Catchable Fatal
Error: Argument 1 passed to
Vendor\Package\Domain\Model\Item_Original::setStopdate() must be an
instance of DateTime, null given, called in
/var/www/flow/Packages/Framework/TYPO3.Flow/Classes/TYPO3/Flow/Reflection/ObjectAccess.php
on line 229 and defined in
/var/www/flow/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/Vendor_Package_Domain_Model_Item.php
line 81
---------------------------------------------
So what do have to do that in my DB a "NULL" is set when i submit
"stopdate" empty ?
Greetings,
Jan
More information about the Flow
mailing list