tobias / zend-paginator-doctrine
Adapter to use Zend\Paginator with Doctrine
Requires
- php: ^7.3
- doctrine/collections: ^1.6
- zendframework/zend-paginator: ^2.8
Requires (Dev)
- phpunit/phpunit: ^8.2
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2020-02-01 19:22:43 UTC
README
Inspired and based on the famous DoctrineModule.
Collection adapter
This package provides a simple Paginator adapter that can be used with DoctrineCollection.
Note : if you are using Doctrine 2 ORM, what you are looking for is probably a Paginator adapter that can be used with Doctrine 2 Paginators. Luckily, DoctrineORMModule provides such a paginator adapter. You can find the documentation here :
Simple example
Here is how you can use the Doctrine paginator adapter :
use Doctrine\Common\Collections\ArrayCollection; use Tobias\Zend\Paginator\Adapter\Collection as CollectionAdapter; use Zend\Paginator\Paginator; // Create a Doctrine 2 Collection $doctrineCollection = new ArrayCollection(range(1, 101)); // Create the adapter $adapter = new CollectionAdapter($doctrineCollection); // Create the paginator itself $paginator = new Paginator($adapter); $paginator->setCurrentPageNumber(1) ->setItemCountPerPage(5); // Pass it to the view, and use it like a "standard" Zend paginator
For more information about Zend Paginator, please read the Zend Paginator documentation.
Selectable adapter
This package also provides another paginator adapter that is based on new Selectable and Criteria interfaces from Doctrine >= 2.3. It works with any Selectable objects (ObjectRepository for instance).
Simple example
You can use it without any existing Criteria object:
use Tobias\Zend\Paginator\Adapter\Selectable as SelectableAdapter; use Zend\Paginator\Paginator; // Create the adapter $adapter = new SelectableAdapter($objectRepository); // An object repository implements Selectable // Create the paginator itself $paginator = new Paginator($adapter); $paginator->setCurrentPageNumber(1) ->setItemCountPerPage(5); // Pass it to the view, and use it like a "standard" Zend paginator
If you want to further filter the results, you can optionally pass an existing Criteria object:
use Doctrine\Common\Collections\Criteria as DoctrineCriteria; use Tobias\Zend\Paginator\Adapter\Selectable as SelectableAdapter; use Zend\Paginator\Paginator; // Create the criteria $expr = DoctrineCriteria::expr()->eq('foo', 'bar'); $criteria = new DoctrineCriteria($expr); // Create the adapter $adapter = new SelectableAdapter($objectRepository, $criteria); // An object repository implements Selectable // Create the paginator itself $paginator = new Paginator($adapter); $paginator->setCurrentPageNumber(1) ->setItemCountPerPage(5); // Pass it to the view, and use it like a "standard" Zend paginator
For more information about Zend Paginator, please read the Zend Paginator documentation.