【问题标题】:cakephp birthday helper customize the default valuescakephp生日助手自定义默认值
【发布时间】:2013-07-01 13:53:42
【问题描述】:

我想在生日菜单助手中添加“月”、“日”、“年”作为首选?这可以做到吗?我没有看到任何有关如何执行此操作的示例?以下是我的代码:

    <?php echo $this->Form->input('date_of_birth', 
        array(
            'type' => 'date',
            'label' => 'Date of Birth:<span>*</span>',
            'dateFormat' => 'MDY',
            'empty' => true,
            'minYear' => date('Y')-130,
            'maxYear' => date('Y'),
            'options' => array('1','2')
            )
        );
    ?>

谢谢, 巴特

【问题讨论】:

  • 不太确定我是否理解你。您是否尝试将实际单词 monthdayyear 作为空选项放在选择列表中?
  • 另外你使用的是哪个 CakePHP 版本?
  • 是的,我正在尝试将“月”、“日”和“年”这些词作为第一个字段。我知道我可以破解核心,但不希望这样做。我还看到他们是一个月份名称数组,适用于月份。我现在只需要得到一天和一年。我正在使用 cakephp 2.3

标签: forms cakephp form-helpers


【解决方案1】:

在这里,the empty option accepts an array 可以使用 monthyeardayhourminutemeridian 键为各个字段指定空值:

echo $this->Form->input('date_of_birth', 
    array(
        'type' => 'date',
        'label' => 'Date of Birth:<span>*</span>',
        'dateFormat' => 'MDY',
        'empty' => array(
            'month' => 'Month',
            'day'   => 'Day',
            'year'  => 'Year'
        ),
        'minYear' => date('Y')-130,
        'maxYear' => date('Y'),
        'options' => array('1','2')
    )
);

【讨论】:

  • 谢谢,我会试一试,告诉你进展如何。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-08
  • 2014-08-08
  • 1970-01-01
  • 1970-01-01
  • 2015-05-31
  • 1970-01-01
相关资源
最近更新 更多