我创建了一个自定义查找类型,并尝试对结果进行分页,但是分页器似乎忽略了findType设置。有人能告诉我我做错了吗?
(CakePHP 2.X)
在我的控制器中:
public function list($username=null) {
$this->Paginator->settings = array(
'Question' => array(
'findType' => 'unanswered',
'conditions' => array('Question.private' => 0),
);
$data = $this->Paginator->paginate('Question');
$this->set('data', $data);
);
在我的模型中自定义查找类型设置:
public $findMethods = array('unanswered' => true);
protected function _findUnanswered($state, $query, $results = array()) {
if ($state == 'before') {
$query['order'] = array('Question.created DESC');
$query['conditions'] = array_merge($query['conditions'], array('Question.date_answered' => ''));
return $query;
$this->log($query);
} elseif ($state == 'after') {
return $results;
}
}
修改的
如果我删除$ this-> Paginate->设置,我可以对查询进行分页,并将其替换为:
$this->paginate = array('unanswered');
但是,我想添加一些额外的条件。,这不起作用:
$this->paginate = array('unanswered' => 'conditions' => array('Question.user_id' => $id, 'limit' => 4)) );
这可能吗?
答案 0 :(得分:1)
findType被添加到CakePHP 2.3中的paginator组件中,我在2.0