将查询转换为cakephp查询

时间:2013-03-28 10:02:38

标签: cakephp cakephp-2.0

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));
谢谢。

1 个答案:

答案 0 :(得分: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'))
));