Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/neutron-pro/neutronstars-pagination


https://github.com/neutron-pro/neutronstars-pagination

Last synced: 14 days ago
JSON representation

Awesome Lists containing this project

README

        

# Pagination API for PHP

![Example Pagination 1](exemples/assets/img/pagination-1.jpg)
![Example Pagination 2](exemples/assets/img/pagination-2.jpg)

#Installation

```
composer require neutronstars/pagination
```
```json
{
"require": {
"neutronstars/pagination": ">=1.1.*"
}
}
```

If you want use the css style:
```html

```

#Example

```php
3,
'key' => ':page',
'url' => '?page=:page',
'build-empty' => false,
'previous-next' => [
'active' => false,
'next-content' => 'Next',
'previous-content' => 'Previous',
'hidden' => true
],
'first-last' => [
'active' => false,
'first-content' => '«',
'last-content' => '»',
'hidden' => true
],
'css' => [
'parent-class' => 'pagination',
'child-class' => 'pagination-item',
'child-class-active' => 'pagination-item-active',
'separator-class' => 'pagination-separator',
'separator-content' => '...',
'previous-next-class' => 'pagination-pn-item',
'previous-next-class-active' => 'pagination-pn-item-active',
'first-last-class' => 'pagination-fl-item',
'first-last-class-active' => 'pagination-fl-item-active'
]
];

$currentPage = 1;
$itemPerPage = 10;
$totalItem = 200;
echo new Pagination($currentPage, $itemPerPage, $totalItem, $options);
```

#Callback

```php
[
'active' => true,
'hidden' => false
],
'previous-next' => [
'active' => true,
'hidden' => false
]
]);

echo $pagination->toHTML(function ($type, $page) use ($pagination) {
switch ($type)
{
case PaginatorCallback::SEPARATOR_TYPE:
return '...';
case PaginatorCallback::FIRST_PAGE_TYPE:
return '';
case PaginatorCallback::PREVIOUS_PAGE_TYPE:
return 'Previous';
case PaginatorCallback::PAGE_TYPE:
return ''.$page.'';
case PaginatorCallback::CURRENT_PAGE_TYPE:
return ''.$page.'';
case PaginatorCallback::NEXT_PAGE_TYPE:
return 'Next';
case PaginatorCallback::LAST_PAGE_TYPE:
return '';
}
return '';
});
```

#PaginatorCallback

```php
pagination = $pagination;
}

public function __invoke(int $type, int $page): string
{
switch ($type)
{
case self::SEPARATOR_TYPE:
return '...';
case self::FIRST_PAGE_TYPE:
return '';
case self::PREVIOUS_PAGE_TYPE:
return 'Previous';
case self::PAGE_TYPE:
return ''.$page.'';
case self::CURRENT_PAGE_TYPE:
return ''.$page.'';
case self::NEXT_PAGE_TYPE:
return 'Next';
case self::LAST_PAGE_TYPE:
return '';
}
return '';
}
}
```

```php
[
'active' => true,
'hidden' => false
],
'previous-next' => [
'active' => true,
'hidden' => false
]
]);

echo $pagination->toHTML(new ExamplePaginatorCallback($pagination));
```