Skip to content

Instantly share code, notes, and snippets.

@markomarkovic
Forked from justinyost/paging.ctp
Created October 25, 2012 11:39
Show Gist options
  • Save markomarkovic/3952134 to your computer and use it in GitHub Desktop.
Save markomarkovic/3952134 to your computer and use it in GitHub Desktop.
Paging Element for Twitter Bootstrap and CakePHP 2.0+
<?php $span = isset($span) ? $span : 8; ?>
<?php $page = isset($this->request->params['named']['page']) ? $this->request->params['named']['page'] : 1; ?>
<?php $pages = (int)$this->Paginator->counter('{:pages}'); ?>
<div class="pagination pagination-centered">
<ul>
<?php echo $this->Paginator->prev(
'&larr; ' . __('Previous'),
array(
'escape' => false,
'tag' => 'li'
),
'<a onclick="return false;">&larr; Previous</a>',
array(
'class'=>'disabled prev',
'escape' => false,
'tag' => 'li'
)
);?>
<?php
$count = $span;
if ($page <= $span / 2) {
$i = 0;
}
if ($page > $span / 2) {
$i = $page - $span / 2;
$count += $i;
}
if ($page > $pages - ($span / 2)) {
$i = $pages - $span;
}
?>
<?php if ($i > 0): ?>
<li class="disabled"><span>&hellip;</span></li>
<?php endif; ?>
<?php while ($i++ < $count): ?>
<?php $options = ''; ?>
<?php if ($i == $page): ?>
<?php $options = ' class="active"'; ?>
<?php endif; ?>
<?php if ($this->Paginator->hasPage($i) && $i > 0): ?>
<li<?php echo $options; ?>><?php echo $this->Paginator->link($i, array('page' => $i)); ?></li>
<?php endif; ?>
<?php endwhile; ?>
<?php if ($this->Paginator->hasPage($i) && $i > 0): ?>
<li class="disabled"><span>&hellip;</span></li>
<?php endif; ?>
<?php echo $this->Paginator->next(
__('Next') . ' &rarr;',
array(
'escape' => false,
'tag' => 'li'
),
'<a onclick="return false;">Next &rarr;</a>',
array(
'class' => 'disabled next',
'escape' => false,
'tag' => 'li'
)
);?>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment