laminas/laminas-paginator
Laminas Paginator provides flexible pagination for PHP apps, with adapters for arrays, iterators, and database results. Generate page ranges and navigation data, and integrate with Laminas MVC or use standalone for paged listings.
Laminas\Paginator is designed to work with laminas-servicemanager as its dependency injection container.
It is perfectly possible to use Paginator without using Laminas Service Manager as the DIC in your project, but some convenience will be sacrificed.
The following configuration would be returned as part of the config service returned from the DI container, so it would be inserted into a PHP file that is autoloaded during bootstrap, or in a ConfigProvider perhaps:
return [
'paginator' => [
'itemCountPerPage' => 10,
'pageRange' => 10,
'scrollingStyle' => 'Sliding',
],
];
The above configures the default page size to 10, the default page range to 10 and uses the Sliding scrolling style by default.
In order for these defaults to apply to newly created paginators, you must use the PaginatorFactory service to delegate construction of your paginators:
use Laminas\Paginator\Adapter\ArrayAdapter;
use Laminas\Paginator\PaginatorFactory;
$factory = $container->get(PaginatorFactory::class);
$paginator = $factory->withAdapter(new ArrayAdapter([1, 2, 3]));
// The paginator above will now be configured with the defaults you have specified.
By using the PaginatorFactory, you can ensure consistent configuration of paginators across your application with a single place where these defaults can be changed, instead of hard-coding preferences into every call to new Paginator(...).
The factory has 2 more methods for building paginators:
use Laminas\Paginator\Adapter\ArrayAdapter;
use Laminas\Paginator\PaginatorFactory;
$factory = $container->get(PaginatorFactory::class);
$paginator = $factory->buildAdapter(ArrayAdapter::class, ['some', 'items', 'to', 'paginate']);
use Laminas\Paginator\Adapter\ArrayAdapter;
use Laminas\Paginator\PaginatorFactory;
$factory = $container->get(PaginatorFactory::class);
$paginator = $factory->withItems(['some', 'items', 'to', 'paginate']);
How can I help you explore Laravel packages today?