[Flow] Optional DateTimeConverter
Jan Greth
jan at greth.me
Sun Oct 5 17:40:17 CEST 2014
Hi Philipp,
*bump* *headonthetable* Thanks a lot!
Sometimes i'm too much into my problems so see the simplest things...
Works like a charm.
Greetings,
Jan
Am 05.10.2014 um 17:06 schrieb Zedd:
> Hi,
>
> with "@ORM\Column(nullable=true)” you merely tell Doctrine to make that column nullable.
> To actually make the property optional, you need to have a function signature like this:
>
> public function setStopDate(\DateTime $stopDate = NULL) {}
>
> Also, setting stopdate to NULL in the constructor does nothing but confuse anyone looking at it.
>
> Greetings
> Philipp
>
> On 05 Oct 2014, at 16:59, Jan Greth <jan at greth.me> wrote:
>
>> 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
>>
>>
>> _______________________________________________
>> Flow mailing list
>> Flow at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>
More information about the Flow
mailing list