1
我有一個子任務和一個馬模型。在CakePHP控制器中過濾日期範圍
馬有許多子任務。
子任務有一個與它關聯的日期。它是一個MYSQL日期對象,不是日期時間。
在我的View/Horse/view.ctp中,我只想打印出給定日期範圍之間的子任務,我很難做到這一點。我可以通過使用常規的過濾子任務,在我的控制器方法:使用
$this->set('incomplete_subtasks', $this->Subtask->find('all', array('conditions' => array(
'and' => array(
'completed ' => 0,
'Subtask.horse_id ' => $id)))));
我想上一個日期範圍過濾此:
$this->set('incomplete_subtasks', $this->Subtask->find('all', array('conditions' => array(
'and' => array(
'completed ' => 0,
'Subtask.horse_id ' => $id,
'Subtask.date BETWEEN ? AND ?' => array(
date(Y-m-d),
date(Y-m-d, strtotime('+1 week'))
)
)
)
)));
我得到了馬/視圖此錯誤:
Notice (8): Use of undefined constant Y - assumed 'Y' [APP/Controller/HorsesController.php, line 56]
我得到我使用的expression-每隔一定的錯誤有六他們總。
引號的工作!謝謝您的幫助 –