Skip to content

Instantly share code, notes, and snippets.

@AndreiTelteu
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreiTelteu/1b3fc56dbb213e8f8e9f to your computer and use it in GitHub Desktop.
Save AndreiTelteu/1b3fc56dbb213e8f8e9f to your computer and use it in GitHub Desktop.
Bootstrap-friendly pagination in CakePHP

Bootstrap-friendly pagination in CakePHP

Put this in your controller .php

<?php
$this->paginate = array(
	'order' => array('field' => 'asc'),
	'limit' => 1,
);
$model = $this->paginate('model', array('condition' => 'here'));
$this->set('model', $model);
?>

And this in your view .ctp

<ul class="pagination">
<?php
if($this->Paginator->hasPrev()) echo "\n\t".$this->Paginator->first("«", array('tag'=>'li'))."\n\t".$this->Paginator->prev("<", array('tag'=>'li'));
echo "\n\t".$this->Paginator->numbers(array('tag' => 'li', 'separator' => "\n\t", 'currentClass' => 'active', 'currentTag' => 'span'));
if($this->Paginator->hasNext()) echo "\n\t".$this->Paginator->next(">", array('tag'=>'li'))."\n\t".$this->Paginator->last("»", array('tag'=>'li'));
echo "\n";
?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment