【问题标题】:Cakephp Custom Find Type PaginationCakephp 自定义查找类型分页
【发布时间】:2013-11-29 10:25:08
【问题描述】:

我创建了一个自定义查找类型,并尝试对结果进行分页,但分页器似乎忽略了 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->settings,我可以对查询进行分页,并将其替换为:

$this->paginate = array('unanswered'); 

但是,我想添加一些附加条件。,这不起作用:

$this->paginate = array('unanswered' => 'conditions' => array('Question.user_id' => $id, 'limit' => 4)) ); 

这可能吗?

【问题讨论】:

  • 如果我删除 $this->Paginate->settings,我可以对查询进行分页,并将其替换为:$this->paginate = array('unanswered');但是,我想添加一些附加条件。也许这是不可能的?

标签: cakephp-2.0


【解决方案1】:

在 CakePHP 2.3 的分页器组件中添加了 findType,我在 2.0 上

http://api.cakephp.org/2.3/class-PaginatorComponent.html

【讨论】:

    猜你喜欢
    • 2019-12-10
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    相关资源
    最近更新 更多