user429511
user429511

Reputation: 53

Cakephp Custom Find Type Pagination

I created a custom find type, and am trying to paginate the results, but the paginator seems to be ignoring the findType setting. Can someone tell me what I'm doing wrong?

(CakePHP 2.X)

In my Controller:

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

Custom find type setup in my Model:

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;
    }
} 

Edit
I can paginate the query if I remove $this->Paginate->settings, and replace it with this:

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

However, I want to add some additional conditions., this doesn't work:

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

Is this possible?

Upvotes: 0

Views: 2597

Answers (1)

user429511
user429511

Reputation: 53

findType was added to the paginator component in CakePHP 2.3, I was on 2.0

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

Upvotes: 1

Related Questions