1
我試圖在每月的日期範圍內爲每位客戶查找所有服務。 在此之後回答問題CakePHP: Date Range我在總結控制器創建此代碼:在日期範圍內查找
public function view($id=null) {
//other code
$this->loadModel('Event');
$summary = $this->Summary->find('first', array('conditions' => array('Summary.id' => $id)));
$first = date('m-01-Y', strtotime($summary['Summary']['date']));
//added this for debugging and the value is the date i want
$this->set('first', $first);
$last = date('m-t-Y', strtotime($summary['Summary']['date']));
//debugging, this works too
$this->set('last', $last);
$conditions = array("'Event.start' >=" => $first, "'Event.start' <=" => $last,
'Event.customer_id' => 'Summary.customer_id'
);
$this->set('events', $this->Event->find('all', array('conditions' => $conditions)));
但在我看來,$事件變量是空的。我也試圖消除customer_id條件來測試日期範圍,問題似乎是'Event.start'無法正確比較。和date()函數不能用在引號內。任何提示?
nope ..仍然是空的。順便說一句,感謝您的快速回復! – 2013-05-14 09:45:39
將請在這裏定義你的日期格式 – liyakat 2013-05-14 10:05:07
哦..也許你明白了。 event.start的格式是datetime,而summary.date只是一個日期。我會嘗試將其更改爲datetime並修改代碼,然後我會通知您。 – 2013-05-14 10:11:31