I'm trying to get CakePHP's pagination helper to play nicely with bootstrap. That is, I want my pagination elements to look like bootstrap's but generated by CakePHP.
At the moment I've got this on my view page:
<?php
echo $this->Paginator->numbers(array(
'before' => '<div class="pagination"><ul>',
'separator' => '',
'currentClass' => 'active',
'tag' => 'li',
'after' => '</ul></div>'
));
?>
Which produces the following markup:
<div class="pagination">
<ul>
<li class="active">1</li>
<li><a href="/test/posts/page:2">2</a></li>
<li><a href="/test/posts/page:3">3</a></li>
</ul>
</div>
The problem is, because the active page (1 in this case) doesn't have an <a>
element in the <li>
tag, it's not displaying correctly on the page (see here: http://i.imgur.com/OczPh.png).
I can't seem to find anything on the Cookbook that mentions anything that would fix this.
Can this even be fixed?
Try this if you are using Twitter Bootstrap 3.0 and CakePHP 2.0 or 2.1:
css (somewhere in your css, not in the bootstrap css!)
CakePHP View (where you want to display the pagination bar)
you can achieve this without any css to add :
So many answers, but non handle ellipsis. Below you can find full version, no custom CSS needed.
CakePHP v2, Bootstrap v3
The resulting code:
All you really need to do is add a CSS class for the current and disabled items to match. Here's one I use for my project (it's basically copied and pasted from the bootstrap CSS file).
This gives it the same style as the
a
tags.