实际上,我想满足这个SQL要求:
... where(type_id = 6 OR type_id = 8)和status = 2 ....
但我不知道如何在$ paginate中设置条件。
var $paginate = array(
'Student'=>array(
'limit' => 10,
'fields'=>array('Student.id','Student.firstname','Student.lastname'),
'order' =>array('Student.id'=>'desc'),
'conditions' => ?,
),
);
任何人都知道如何设定条件?
答案 0 :(得分:2)
基于此网站http://book.cakephp.org/1.3/view/1030/Complex-Find-Conditions (这不是长篇大论,但试试吧)
var $paginate = array(
'Student'=>array(
'limit' => 10,
'fields'=>array('Student.id','Student.firstname','Student.lastname'),
'order' =>array('Student.id'=>'desc'),
'conditions' => array(
'Student.type_id' => array(6, 8),
'Student.status' => 2
)
),
);
或
var $paginate = array(
'Student'=>array(
'limit' => 10,
'fields'=>array('Student.id','Student.firstname','Student.lastname'),
'order' =>array('Student.id'=>'desc'),
'conditions' => array(
'Student.status' => 2,
"OR" => array (
'Student.type_id' => 6,
'Student.type_id' => 8
)
)
),
);
编辑:在这种情况下不能使用第二个版本,因为现在OR数组有两个具有相同键的元素,并且只会检查最后一个(8)
[N.B。]对不起,如果我犯了一些语法错误:)