Marc
Marc

Reputation: 493

CakePHP paginator limit box

Right now im using pagination to control my pages however i would like to add a combobox where there is a option where the user can set how many results he / she wants to see per site.

Paginator

Has a lot of options build in such as paging counting and so on so i was wondering if anyone knows if there is a buildin method for this aswell?

Upvotes: 0

Views: 576

Answers (1)

timstermatic
timstermatic

Reputation: 1740

You can change this on-the-fly in your controller method:

 $this->paginate = array('limit'=>10);

Directly before your paginate call. So, you could pass this on as a named parameter such as limit:10 and then do:

$this->paginate = array('limit'=>$this->params['named']['limit']);

Here is a fuller example that assumes you are posting a form.

In your view:

<?php echo $this->Form->create();?>
<?php echo $this->Form->input('limit', array('options'=>array(10=>10, 20=>20, 30=>30)));?>
<?php echo $this->Form->submit('Show');?>
<?php echo $this->Form->end()?>

In your controller method:

if(!empty($this->request->data['limit'])) {
   $this->paginate = array('limit'=>$this->request->data['limit']);
}

Upvotes: 2

Related Questions