我有一组出生日期的选择:
<?php echo $this->Form->input('Profile.dob', array('label' => 'Date of Birth'
, 'dateFormat' => 'DMY'
, 'minYear' => date('Y') - 100
, 'maxYear' => date('Y') - 13)); ?>
并希望在选择中将默认设置为单词“DAY MONTH YEAR”。
我已经设法用性别来做到这一点:
<?php echo $this->Form->input('Profile.gender', array('label' => 'Gender', 'type' => 'select',
'options' => array('Male'=>'Male','Female'=>'Female'),'empty'=>'Select Sex')); ?>
但我不知道如何使用自动日期输入...
有人可以帮忙吗?谢谢
最佳答案
只需添加:
'selected'=>date('Y-m-d')
到您的选项数组。
该示例将显示当前日期。如果您需要静态日期,请根据需要替换它。例如:
'selected'=>'2011-12-10'
显然对于日期和时间,使用:
'selected'=>date('Y-m-d H:i:s')
或
'selected'=>'2011-12-10 11:13:45'
关于php - CakePHP 日期选择的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8688205/