3

我想将用户选择的日期限制为仅限星期一。

我将日期字段存储在 MySQL 数据库中,当我使用echo $this->Form->input('date');. 但它会生成年、月和日的下拉菜单。这似乎不是将用户选择限制为每月四五天的好方法。

我查看了 CakePHP 站点上可用于日期时间输入字段的选项,这interval与我需要的完全一样,但它仅适用于日期时间字段上的分钟框,并且似乎对日期字段没有影响。

有没有一种干净的 CakePHP 方法来解决这个问题,或者我只是自己生成日期列表并创建一个包含这些值的下拉框?

谢谢!

4

1 回答 1

1

如果你想有一个漂亮的 UI 使用 Jquery DatePicker

//Cake view
    echo $this->Form->input('created', array('type'=>'text', 'id'=>'created'));

//Jquery 
    $('#created').datepicker({
         dateFormat : 'yy-mm-dd'
    });   

否则你可以限制日期输入

//Year
echo $this->Form->year('purchased-year', 2000, date('Y'));
//Month
echo $this->Form->month('mob');
//Day
echo $this->Form->day('created');

FormHelper::hour(string $fieldName, boolean $format24Hours, array $attributes)
Creates a select element populated with the hours of the day.

FormHelper::minute(string $fieldName, array $attributes)
Creates a select element populated with the minutes of the hour.

FormHelper::meridian(string $fieldName, array $attributes)
Creates a select element populated with ‘am’ and ‘pm’.

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#creating-date-and-time-inputs

于 2014-04-04T16:45:48.483 回答