John Dorean
John Dorean

Reputation: 3874

CakePHP ignoring $paginate property

I've just baked a simple CakePHP app, and I'm trying to customize how records are paginated. I have this action in my controller:

public function index() {
    $this->Recipe->recursive = 0;
    $this->set('recipes', $this->Recipe->paginate());
}

This works fine with the default pagination. I'm trying to customize the amount of rows returned and their order by using a class property called $paginate in the same controller:

public $paginate = array(
    'limit' => 1,
    'order' => array(
        'Recipe.title' => 'asc'
    )
);

However it's taking no effect at all. The results still have the default limit and sort order. I've also tried setting up $this->paginate in my action, however this seems to get ignored also:

public function index() {
    $this->paginate = array(
        'limit' => 1,
        'order' => array(
            'Recipe.title' => 'asc'
        )
    );
    $this->set('recipes', $this->Paginator->paginate());
}

What could be causing Cake to ignore the pagination options I'm setting? Does it perhaps do something funky when you bake the application which I'm not aware of?

Upvotes: 1

Views: 992

Answers (1)

floriank
floriank

Reputation: 25698

Try

public function index() {
    $this->Paginator->settings = array(
        'limit' => 1,
        'order' => array(
            'Recipe.title' => 'asc'
        )
    );
    $this->set('recipes', $this->Paginator->paginate());
}

Upvotes: 2

Related Questions