tobias / zend-paginator-doctrine
此包已被废弃,不再维护。未建议替代包。
适配器,用于将Zend\Paginator与Doctrine一起使用
dev-master
2019-07-01 07:52 UTC
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
受著名的DoctrineModule启发并基于其构建。
集合适配器
此包提供了一个简单的Paginator适配器,可以与DoctrineCollection一起使用。
注意:如果您正在使用Doctrine 2 ORM,您可能需要的是一个可以与Doctrine 2 Paginators一起使用的Paginator适配器。幸运的是,DoctrineORMModule提供了这样的适配器。您可以在以下链接中找到文档
简单示例
以下是如何使用Doctrine paginator适配器的示例
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
有关Zend Paginator的更多信息,请参阅Zend Paginator文档。
可选适配器
此包还提供了一个基于Doctrine >= 2.3的新Selectable和Criteria接口的另一个paginator适配器。它适用于任何Selectable对象(例如ObjectRepository)。
简单示例
您可以在没有现有Criteria对象的情况下使用它
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
如果您想进一步过滤结果,您可以可选地传递一个现有的Criteria对象
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
有关Zend Paginator的更多信息,请参阅Zend Paginator文档。