Skip to content

Instantly share code, notes, and snippets.

@motsmanish
Created October 5, 2020 09:38
Show Gist options
  • Save motsmanish/c1827ca6c0faa49899bebef09af3f8b9 to your computer and use it in GitHub Desktop.
Save motsmanish/c1827ca6c0faa49899bebef09af3f8b9 to your computer and use it in GitHub Desktop.
Pagination code for Cakephp 4 + Bootstrap 4
<?php
$this->Paginator->setTemplates([
'first' => '<li class="page-item"><a class="page-link" href="{{url}}">{{text}}</a></li>',
'prevActive' => '<li class="page-item"><a class="page-link" href="{{url}}">{{text}}</a></li>',
'prevDisabled' => '<li class="page-item disabled"><a class="page-link" href="{{url}}">{{text}}</a></li>',
'current' => '<li class="page-item"><a class="page-link" href="{{url}}">{{text}}</a></li>',
'number' => '<li class="page-item"><a class="page-link" href="{{url}}">{{text}}</a></li>',
'nextActive' => '<li class="page-item"><a class="page-link" href="{{url}}">{{text}}</a></li>',
'nextDisabled' => '<li class="page-item disabled"><a class="page-link" href="{{url}}">{{text}}</a></li>',
'last' => '<li class="page-item"><a class="page-link" href="{{url}}">{{text}}</a></li>'
]);
?>
<div class="mx-auto">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-end">
<?= $this->Paginator->first('first') ?>
<?= $this->Paginator->prev('previous') ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next('next') ?>
<?= $this->Paginator->last('last') ?>
</ul>
</nav>
<?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
</div>
@motsmanish
Copy link
Author

This is how it looks:
image

@impronta48
Copy link

Very well done. Do you know where we can put this template so that it applies to every paginator?

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