2
where concat(`year`,'-',`month`)  BETWEEN '2013-02'  AND '2013-03';

如何像这样在cake php的自定义查询分页中使用此查询..

$conditions = array('concat('Payroll.year','-','Payroll.month')  BETWEEN ? and ?' => array(2013-02, 2013-03));

$staff_list =  $this->Payroll->find("all", array("fields" => array("Payroll.id", "Payroll.month", "Payroll.year"),"conditions"=>$conditions));

谢谢你。

4

1 回答 1

2

是的,你可以这样做: 在你的模型中

var $virtualFields = array(
    'payroll_date' => 'CONCAT(Payroll.year, " ", Payroll.month)'
);

在控制器中

$staff_list =  $this->Payroll->find("all", array(
  "fields" => array("Payroll.id", "Payroll.month", "Payroll.year"),
  "conditions" => array('Payroll.payroll_date BETWEEN ? AND ?' => array('2013-02', '2013-03'))
));
于 2013-03-28T10:36:15.820 回答