Example #1
0
include "Bootstrap3.php";
$pagination = new Pagination();
$pagination->setTotalItems(105)->setProximity(2)->setItemsPerPage(10);
// same as setLimit()
?>
<html>
<head>
	<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" />
<style>
body {
	max-width: 580px;
	margin: 20px auto;
}
</style>
</head>
<body>
<h3>Bootstrap3 Pagination</h3>
<?php 
echo Bootstrap3::renderPagination($pagination->toArray());
?>
<h3>Bootstrap3 Pager</h3>
<?php 
echo Bootstrap3::renderPager($pagination->toArray());
?>
<h3>Bootstrap3 Aligned Pager</h3>
<?php 
echo Bootstrap3::renderAlignedPager($pagination->toArray());
?>
</body>
</html>
Example #2
0
 public function testRealExample()
 {
     $pagination = new Pagination();
     $pagination->setTotalItems(105)->setItemsPerPage(10)->setUri("/posts?page=5");
     $this->assertSame(5, $pagination->getPage());
     $this->assertSame(11, $pagination->getTotalPages());
     $pages = $pagination->toArray();
     // always should have "prev" and "next"
     $this->assertArrayHasKey("prev", $pages);
     $this->assertArrayHasKey("next", $pages);
     // previous | first | 4 before | selected | 4 after | last | next
     $this->assertSame(13, count($pages));
     // Test with proximity 3
     $pagination->setProximity(3);
     $pages = $pagination->toArray();
     $this->assertSame(11, count($pages));
     // Test with proximity 2
     $pagination->setProximity(2);
     $pages = $pagination->toArray();
     $this->assertSame(9, count($pages));
     // Test with proximity 1
     $pagination->setProximity(1);
     $pages = $pagination->toArray();
     $this->assertSame(7, count($pages));
     // Test with proximity 0
     // previous | first | current | last | next
     $pagination->setProximity(0);
     $pages = $pagination->toArray();
     $this->assertSame(5, count($pages));
 }