Pagination
class Pagination extends Plugin implements IteratorAggregate, JsonSerializable
Pagination accepts a pagination object generated by the Builder system to create a loopable set of objects you can include in a template.
$builder = $this->getDI()->getArticleManager()->getBuilder()
->setPage($page)
->setLimit($perPage)
->byTags($section->tags)
->paginate();
$articles = $builder->getItems();
$paginator = (new Pagination)
->setPagination($builder->getPagination())
->setLimit($perPage)
->build();
Then in your template
{% for page in paginator %}
<a href="{{ page.url }}">{{ page.label }}</a>
{% endfor %}
Methods
Create new paginator If no url is provided, will use current.
Set number of pages to show for sliding pagination
Set the number of items per page
Set the pagination object
Set extra query params, note that reserved words will be unset
Set the base pagination URL. Will substitute page and per_page attributes
Get first page
Get last page
Get next page
Get previous page
Get all numbered pages, e.g. not first/last and next/previous
Force a rebuild of pagination. Really only useful if you reset the pagination object or url options after building
Build pagination. Called automatically on first attempt to access pages
Allow for iterator access
Allow for proper JSON serialization
Details
at line 63
__construct(stdClass $pagination = [], string $url = false)
Create new paginator If no url is provided, will use current.
at line 80
Pagination
setShow(int $pages)
Set number of pages to show for sliding pagination
at line 91
Pagination
setLimit(int $limit)
Set the number of items per page
at line 102
Pagination
setPagination(stdClass $pagination)
Set the pagination object
at line 113
Pagination
setParams(array $params = [])
Set extra query params, note that reserved words will be unset
at line 137
Pagination
setUrl(string $url)
Set the base pagination URL. Will substitute page and per_page attributes
at line 174
object
getFirst()
Get first page
at line 184
object
getLast()
Get last page
at line 194
object
getNext()
Get next page
at line 204
object
getPrevious()
Get previous page
at line 214
array
getPages()
Get all numbered pages, e.g. not first/last and next/previous
at line 225
Pagination
rebuild()
Force a rebuild of pagination. Really only useful if you reset the pagination object or url options after building
at line 238
Pagination
build()
Build pagination. Called automatically on first attempt to access pages
at line 312
ArrayIterator
getIterator()
Allow for iterator access
at line 322
Array
jsonSerialize()
Allow for proper JSON serialization