Created
March 20, 2012 16:05
-
-
Save justinyost/2137554 to your computer and use it in GitHub Desktop.
Paging Element for Twitter Bootstrap and CakePHP 2.0+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $span = isset($span) ? $span : 8; ?> | |
<?php $page = isset($this->request->params['named']['page']) ? $this->request->params['named']['page'] : 1; ?> | |
<div class="pagination"> | |
<ul> | |
<?php echo $this->Paginator->prev( | |
'← ' . __('Previous'), | |
array( | |
'escape' => false, | |
'tag' => 'li' | |
), | |
'<a onclick="return false;">← Previous</a>', | |
array( | |
'class'=>'disabled prev', | |
'escape' => false, | |
'tag' => 'li' | |
) | |
);?> | |
<?php $count = $page + $span; ?> | |
<?php $i = $page - $span; ?> | |
<?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->Html->link($i, array("page" => $i)); ?></li> | |
<?php endif; ?> | |
<?php $i += 1; ?> | |
<?php endwhile; ?> | |
<?php echo $this->Paginator->next( | |
__('Next') . ' →', | |
array( | |
'escape' => false, | |
'tag' => 'li' | |
), | |
'<a onclick="return false;">Next →</a>', | |
array( | |
'class' => 'disabled next', | |
'escape' => false, | |
'tag' => 'li' | |
) | |
);?> | |
</ul> | |
</div> |
This came in handy. Thanks for the element.
It worked! Thank you. :)
Thanks!
Worked like a charm. Thanks. :)
Paginator has all options to create a bootstrap structure.
currentTag - Tag to use for current page number, defaults to null. This allows you to generate for example Twitter Bootstrap like links with the current page number wrapped in extra ‘a’ or ‘span’ tag.
CakePHP: 2.3.1
Bootstrap: 2.3.1
<?php
$params = $this->Paginator->params();
if ($params['pageCount'] > 1) {
?>
<div class="pagination">
<ul>
<?php
echo $this->Paginator->prev('← Previous', array(
'class' => 'prev',
'tag' => 'li',
'escape' => false
), '<a onclick="return false;">← Previous</a>', array(
'class' => 'prev disabled',
'tag' => 'li',
'escape' => false
));
echo $this->Paginator->numbers(array(
'separator' => '',
'tag' => 'li',
'currentClass' => 'active',
'currentTag' => 'a'
));
echo $this->Paginator->next('Next →', array(
'class' => 'next',
'tag' => 'li',
'escape' => false
), '<a onclick="return false;">Next →</a>', array(
'class' => 'next disabled',
'tag' => 'li',
'escape' => false
)); ?>
</ul>
</div>
<?php } ?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great stuff. Worked right out of the box. Thank you.