Instantly share code, notes, and snippets.

Embed
What would you like to do?
pagination element for CakePHP on twitter bootstrap
<?php
if (!isset($modules)) {
$modulus = 11;
}
if (!isset($model)) {
$models = ClassRegistry::keys();
$model = Inflector::camelize(current($models));
}
?>
<div class="pagination">
<ul>
<?php echo $this->Paginator->first('<<', array('tag' => 'li')); ?>
<?php echo $this->Paginator->prev('<', array(
'tag' => 'li',
'class' => 'prev',
), $this->Paginator->link('<', array()), array(
'tag' => 'li',
'escape' => false,
'class' => 'prev disabled',
)); ?>
<?php
$page = $this->params['paging'][$model]['page'];
$pageCount = $this->params['paging'][$model]['pageCount'];
if ($modulus > $pageCount) {
$modulus = $pageCount;
}
$start = $page - intval($modulus / 2);
if ($start < 1) {
$start = 1;
}
$end = $start + $modulus;
if ($end > $pageCount) {
$end = $pageCount + 1;
$start = $end - $modulus;
}
for ($i = $start; $i < $end; $i++) {
$url = array('page' => $i);
$class = null;
if ($i == $page) {
$url = array();
$class = 'active';
}
echo $this->Html->tag('li', $this->Paginator->link($i, $url), array(
'class' => $class,
));
}
?>
<?php echo $this->Paginator->next('>', array(
'tag' => 'li',
'class' => 'next',
), $this->Paginator->link('>', array()), array(
'tag' => 'li',
'escape' => false,
'class' => 'next disabled',
)); ?>
<?php echo str_replace('<>', '', $this->Html->tag('li', $this->Paginator->last('>>', array(
'tag' => null,
)), array(
'class' => 'next',
))); ?>
</ul>
</div>
@jtraulle

This comment has been minimized.

jtraulle commented Jul 18, 2012

Guy, you rock !
Many thanks !

@martinschenk

This comment has been minimized.

martinschenk commented Jul 25, 2012

perfect! thank you.

@pasela

This comment has been minimized.

pasela commented Jul 31, 2012

Great stuff! but I think the variable of the 2nd line is not $modules but $modulus.

@slywalker

This comment has been minimized.

Owner

slywalker commented Jul 31, 2012

I don't maintain this code.
If you use CakePHP2.x, please refer to url.

https://github.com/slywalker/TwitterBootstrap

@itogen

This comment has been minimized.

itogen commented Jul 11, 2013

Great work!
ありがとう!

@vibhasbhingarde

This comment has been minimized.

vibhasbhingarde commented Jul 12, 2014

Perfect ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment