CakePHP Increase Year Range in Drop Down

江枫思渺然 提交于 2019-12-01 13:57:32

问题


In CakePHP, if i keep a table field type as date, then it shows dropdown with month, day and year. However, the year range starts from 1990 only, how can I change it to start from 1900?


回答1:


You can use minYear and maxYear options of an input like this:

<?php

echo $this->Form->input('birth_dt', array(
    'label' => 'Date of birth', 
    'dateFormat' => 'DMY',
    'minYear' => date('Y') - 70,
    'maxYear' => date('Y') - 18 ));

?>

Reference to cakePHP Cookbook

FYI: If current year is 2017 date('Y') - 70 will be 1947 [2017 - 70 = 1947].



来源:https://stackoverflow.com/questions/5855451/cakephp-increase-year-range-in-drop-down

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!