What is the best way to limit a date range in a CakePHP view?

I have a date field which the users of the system can edit, but there are limitations on what they may be able to select. Right now it is simple and just limited to "n" number of days into the future. But I could see it getting more sophisticated with only allowing weekdays, etc. I can write the select elements manually, but I'm curious if there are any helpers that have started tackling this.

Answers


There is nothing that I have found. But this should be simple enough to create:

// populate with the weekdays you want (0=Sunday, 1=Monday, etc.)
$weekdays = array(1,2,3,4,5);

$dates = array();
$today = strtotime(date("Y-m-d"));
$end_date = strtotime("+6 months");
while($today < $end_date) {
    $weekday = date("w", $today);
    if (in_array($weekday, $weekdays)) {
        array_push($dates, date("Y-m-d", $today));
    }
    $today += 86400;
}

$this->set('dates', $dates)

Then in the view:

$this->Form->input('my_date', array('type' => 'select', 'options' => $dates));

Need Your Help

Reset/Remove samrtTable filter on object

angularjs filter smart-table

I'm using SmartTable in AngularJS to display a list of records.

Disable TCP Delayed ACKs

linux tcp

I have an application that receives relatively sparse traffic over TCP with no application-level responses. I believe the TCP stack is sending delayed ACKs (based on glancing at a network packet c...