我试图在每月的日期范围内为每个客户查找所有服务。按照这个回答的问题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)));
但是我认为 $events 变量是空的。我还尝试消除 customer_id 条件来测试日期范围,问题似乎是无法正确比较“Event.start”。和 date() 函数不能在引号内使用。任何提示?