有没有办法在CakePHP日期表单输入中设置默认日期?
问题描述:
我有这个:
<?php echo $this->Form->input('Schedule.0.end_date', array(
'minYear' => date('Y'),
'maxYear' => date('Y')+5
)); ?>
我想将默认日期设置为今天以外的日期。这是可能与CakePHP的形式助手吗?
I would like to set the default date to something other than today. Is this possible with CakePHP's form helper?
我发现一个帖子,显示如何做到与TIME - 但尝试类似的设置天,月
I found a post that showed how do to it with TIME - but trying something similar by setting "day", "month", "year" does nothing.
答
您可以使用 selected
$ this-> Form-> input();
的参数。尝试这样:
You can achieve that using the selected
parameter of $this->Form->input();
. Try like this:
<?php
echo $this->Form->input('datetime', array(
'label' => 'Date 1',
'selected' => array(
'day' => '',
'month' => '',
'year' => '',
'hour' => '',
'minute' => '',
'second' => ''
)
));
/* What's interesting... this will work aswell: */
echo $this->Form->input('datetime', array(
'label' => 'Date 2',
'selected' => '0000-00-00 00:00:00'
));
?>