Last active
July 24, 2017 22:47
-
-
Save natanfelles/9f4ccf4d10dd0dbf72599b26bd11ec0a to your computer and use it in GitHub Desktop.
CodeIgniter 4 - Header Link Pagination
This file contains hidden or 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 | |
/** | |
* CodeIgniter 4 - Header Link Pagination | |
* | |
* Usage: | |
* | |
* $this->response->setHeader('Link', $pager->links('default', 'header_link')) | |
* | |
* @author Natan Felles <[email protected]> | |
* @link https://gist.github.com/natanfelles/9f4ccf4d10dd0dbf72599b26bd11ec0a | |
* @see http://tools.ietf.org/html/rfc5988 | |
* @see https://bcit-ci.github.io/CodeIgniter4/libraries/response.html#setting-headers | |
* @see https://bcit-ci.github.io/CodeIgniter4/libraries/pagination.html | |
*/ | |
$pager->setSurroundCount(0); | |
$links = ''; | |
if ($pager->hasPrevious()) | |
{ | |
$links .= '<' . $pager->getFirst() . '>; rel="first",'; | |
$links .= '<' . $pager->getPrevious() . '>; rel="prev"'; | |
} | |
if ($pager->hasPrevious() && $pager->hasNext()) | |
{ | |
$links .= ','; | |
} | |
if ($pager->hasNext()) | |
{ | |
$links .= '<' . $pager->getNext() . '>; rel="next",'; | |
$links .= '<' . $pager->getLast() . '>; rel="last"'; | |
} | |
echo $links; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment