Nette\Utils\DateTime as persistent presenter parameter

dTTb
Member | 30
+
0
-

Hello

I'm trying to use Nette\Utils\DateTime as persistent parameter, but Presenter by default accepts only scalar parameters (described in Czech https://phpfashion.com/…na-nette-2-1#… – in short it says “if you want to use array, specify it as default”). So when I try

<?php
    /** @persistent */
    public $date;

    public function beforeRender() {
        parent::beforeRender();

        $this->date = new \DateTime;
	}

?>

I get Value passed to persistent parameter ‘date’ in presenter Order must be scalar, array given., but $this->date is actually instance of DateTime. Anyway I tried to fix it with

<?php
    /** @persistent */
    public $date = array();
?>

I got Value passed to persistent parameter ‘date’ in presenter Order must be array, DateTime given.

I also tried many variants of

<?php
    /** @persistent */
    public $date = \DateTime;
?>

but it usually results in syntax error or undefined constant…

Is there any way, how could I convince presenter to accept DateTime parameter (@var annotation maybe [not working yet])?

Thank you
Radek

Nette 2.4. php 5.6.30.

CZechBoY
Member | 3608
+
0
-

Only option is to persistent some scalar value (in this case unix timestamp for example) and store timestamp in the end and on start make datetime from timestamp.