Puja-Paginator is a flexible component for paginating collections of data and presenting that data to users.
Puja-Paginator is a flexible component for paginating collections of data and presenting that data to users., (*1)
Just run this on the command line:, (*2)
composer require jinnguyen/puja-paginator
include '/path/to/vendor/autoload.php'; use Puja\Paginator\Paginator;
Simple, (*3)
$paginator = new Paginator( '/news/', // url 100, // total of records 10 // number of records per page );
The rest of the documentation will assume you have a $paginator
instance on which you are making calls., (*4)
$paginator->addRenderer('simple', 'Puja\Paginator\Renderer\Simple'); // Puja\Paginator\Renderer\Simple must be extended of Puja\Paginator\Renderer\RendererAbstract
$paginator->setLabels($labes); // default $labels is [First, Prev, Next, Last]
The first/last css classes are the class of first/last Breadcrumb element, (*5)
$paginator->setFirstCssClassName($className); $paginator->setLastCssClassName($className); $paginator->setCurrentCssClassName($className);
The default paging element is <li class="{CssClassName}">%s{Divider}</li>
. To change it, use the setElement method like so:, (*6)
$paginator->setElement('<span class="{FirstLastCss}">%s{Divider}</span>');
Note:, (*7)
"%s" is required for Paginator::$element {CssClassName}: will be replaced by Paginator::$firstCssClassName/Paginator::$currentCssClassName/Paginator::$lastCssClassName if this element is first/current/last element. {Divider}: will be replaced by Paginator::$divider
The default list element used to wrap the paging, is <ul>%s</ul>
. To change it, use the setListElement method like so:, (*8)
$paginator->setListElement('<ol class="ol-paging">%s</ol>');
Note:, (*9)
"%s" is required for Paginator::$listElement
The default divider is `` (empty). This will be replace to placeholder {Divider} in property Paginator::$element. If you'd like to change it to, for example, /
, you can just do:, (*10)
$paginator->setDivider('/');
Finally, when you actually want to display your breadcrumbs, all you need to do is call the render()
method on the instance:, (*11)
echo $paginator->render('simple'); echo $paginator->render('basic'); echo $paginator->render(); // default is `basic`
Note, (*12)
You can write custom Renderer by yourself. You can check Puja\Paginator\Renderer\Simple as a sample
Example, (*13)
class CustomRenderer extends \Puja\Paginator\Renderer\RendererAbstract { public function parse() { $p = ''; for ($i = 0; $i < $this->paginator->getTotalPage(); $i++) { $p .= $this->paginator->getPageElement($i, true); } return $p; } } $paginator->addRenderer('custom', 'CustomRenderer'); $paginator->render('custom');
Note that by default First/Prev/Next/Last titles are rendered with escaping HTML characters, if you'd like to ignore it just do like so:, (*14)
$paginator->setSafeHtml(false);