1
        $dts = new DateTime(AppController::getSetting('event_start'));
        $dtf = new DateTime(AppController::getSetting('event_finish'));        

        //CONTROLLER
...
        $weekdays = array(0,1,2,3,4,5,6);

        $dates = array();
        $today = strtotime(date("Y-m-d", $dts->getTimestamp()));
        $end_date = strtotime(date("Y-m-d", $dtf->getTimestamp()));
        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);
...



//VIEW
...
    echo $this->Form->input('date', array('options'=> $dates));
...

dts 和 dtf 是我从数据库中获取的开始和结束日期...

当我从视图中的下拉框中选择一个日期时,它可以提交,但我在数据库中得到的只是 0000-00-00?

我在这里做错了什么?

编辑

我的数组输出

Debugger::dump($dates);

    array(
(int) 0 => '2013-04-01',
(int) 1 => '2013-04-02',
(int) 2 => '2013-04-03',
(int) 3 => '2013-04-04',
(int) 4 => '2013-04-05',
(int) 5 => '2013-04-06',
(int) 6 => '2013-04-07'
)

编辑这就是我的查询的样子

INSERT INTO cake.tickets (first_name, last_name, email, phone, date, quantity) VALUES ('brbt', 'trbb', 'ver@fvef.com', 765657, //THIS IS THE DATE//2, 2) .

好像只能输入key?

4

1 回答 1

2

使您的键和值相同。关键是保存的内容,价值是用户看到的内容。

$dates = array();
$today = strtotime(date("Y-m-d", $dts->getTimestamp()));
$end_date = strtotime(date("Y-m-d", $dtf->getTimestamp()));
while($today <= $end_date) 
{
    $weekday = date("w", $today);
    if (in_array($weekday, $weekdays)) 
    {
        $dates[date("Y-m-d", $today)] = date("Y-m-d", $today);
    }
    $today += 86400;
}
$this->set('dates', $dates);

您的日期数组现在应该如下所示:

array(
 '2013-04-01' => '2013-04-01',
 '2013-04-02' => '2013-04-02',
 '2013-04-03' => '2013-04-03',
 '2013-04-04' => '2013-04-04',
 '2013-04-05' => '2013-04-05',
 '2013-04-06' => '2013-04-06',
 '2013-04-07'=> '2013-04-07'
)

这将生成正确的选择选项。

于 2013-03-05T20:53:12.343 回答