简体   繁体   中英

cakephp form helper for a date: how to make minYear and maxYear work

I'm trying to implement a date selector in Cake-1.3. The problem I'm having is that I've not been able to confine the year selector to the desired set of years, which is 2012 through the current year, whatever that might be. I've tried 3 or 4 ways of coding this, based on my own thoughts and on examples from the cakephp site, Stack Overflow, and at least one other site. No matter which approach I take, the years in the selection list range from 1994 to 2034.

Here is the current version of the code for this:

echo "<div class='date'>" . $this->Form->input('start_date', 
    array('type'=>'date',
        'default'=>array('month'=>$yesterday['month'],
        'day'=>$yesterday['mday'],
        'year' => $today['year'],
         array('dateFormat' => 'MDY', 'minYear' => 2012, 'maxYear' => $yesterday['year'],
          selected)
        )
    )
) . "</div>";

Any suggestions would be highly appreciated.

Your input options should all be in a single unnested array.

echo "<div class='date'>" . $this->Form->input('start_date', 
    array('type'=>'date',
        'default'=>array('month'=>$yesterday['month'],
         'day'=>$yesterday['mday'],
         'year' => $today['year']),
         'dateFormat' => 'MDY', 
         'minYear' => 2012, 
         'maxYear' => $yesterday['year']
    )
)
. "</div>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM