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

__construct(stdClass $pagination = [], string $url = false)

Create new paginator If no url is provided, will use current.

setShow(int $pages)

Set number of pages to show for sliding pagination

setLimit(int $limit)

Set the number of items per page

setPagination(stdClass $pagination)

Set the pagination object

setParams(array $params = [])

Set extra query params, note that reserved words will be unset

setUrl(string $url)

Set the base pagination URL. Will substitute page and per_page attributes

object
getFirst()

Get first page

object
getLast()

Get last page

object
getNext()

Get next page

object
getPrevious()

Get previous page

array
getPages()

Get all numbered pages, e.g. not first/last and next/previous

rebuild()

Force a rebuild of pagination. Really only useful if you reset the pagination object or url options after building

build()

Build pagination. Called automatically on first attempt to access pages

ArrayIterator
getIterator()

Allow for iterator access

Array
jsonSerialize()

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.

Parameters

stdClass $pagination pagination object
string $url default url

at line 80
Pagination setShow(int $pages)

Set number of pages to show for sliding pagination

Parameters

int $pages

Return Value

Pagination

at line 91
Pagination setLimit(int $limit)

Set the number of items per page

Parameters

int $limit @limit

Return Value

Pagination

at line 102
Pagination setPagination(stdClass $pagination)

Set the pagination object

Parameters

stdClass $pagination

Return Value

Pagination

at line 113
Pagination setParams(array $params = [])

Set extra query params, note that reserved words will be unset

Parameters

array $params

Return Value

Pagination

at line 137
Pagination setUrl(string $url)

Set the base pagination URL. Will substitute page and per_page attributes

Parameters

string $url @url

Return Value

Pagination

at line 174
object getFirst()

Get first page

Return Value

object Ceo\Pagination\Url

at line 184
object getLast()

Get last page

Return Value

object Ceo\Pagination\Url

at line 194
object getNext()

Get next page

Return Value

object Ceo\Pagination\Url

at line 204
object getPrevious()

Get previous page

Return Value

object Ceo\Pagination\Url

at line 214
array getPages()

Get all numbered pages, e.g. not first/last and next/previous

Return Value

array of Ceo\Pagination\Url

at line 225
Pagination rebuild()

Force a rebuild of pagination. Really only useful if you reset the pagination object or url options after building

Return Value

Pagination

at line 238
Pagination build()

Build pagination. Called automatically on first attempt to access pages

Return Value

Pagination

at line 312
ArrayIterator getIterator()

Allow for iterator access

Return Value

ArrayIterator

at line 322
Array jsonSerialize()

Allow for proper JSON serialization

Return Value

Array