本文整理汇总了PHP中Pagerfanta\Pagerfanta::setAllowOutOfRangePages方法的典型用法代码示例。如果您正苦于以下问题:PHP Pagerfanta::setAllowOutOfRangePages方法的具体用法?PHP Pagerfanta::setAllowOutOfRangePages怎么用?PHP Pagerfanta::setAllowOutOfRangePages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pagerfanta\Pagerfanta
的用法示例。
在下文中一共展示了Pagerfanta::setAllowOutOfRangePages方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetCurrentPageShouldNormalizePageWhenOutOfRangePageAndIndicatingNormalizeOutOfRangePages
public function testSetCurrentPageShouldNormalizePageWhenOutOfRangePageAndIndicatingNormalizeOutOfRangePages()
{
$this->setAdapterNbResultsAny(100);
$this->pagerfanta->setMaxPerPage(10);
$this->pagerfanta->setAllowOutOfRangePages(false);
$this->pagerfanta->setNormalizeOutOfRangePages(true);
$this->pagerfanta->setCurrentPage(11);
$this->assertSame(10, $this->pagerfanta->getCurrentPage());
}
示例2: paginate
/**
* @param FilterInterface $filter
* @param $searchParams
* @param $page
* @param $maxPerPage
* @param Pagerfanta $pagerfanta
* @return array
*/
public function paginate($filter, $searchParams, $page, $maxPerPage, &$pagerfanta = null)
{
/** @var QueryBuilder $qb */
$qb = $this->createQueryBuilder('x');
$query = FilterBuilder::create()->setQueryBuilder($qb)->setFilter($filter)->buildQuery($searchParams)->getQuery();
$adapter = new DoctrineORMAdapter($query, true, false);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setAllowOutOfRangePages(true)->setMaxPerPage($maxPerPage)->setCurrentPage($page);
return iterator_to_array($pagerfanta->getCurrentPageResults());
}
示例3: serializePagerfanta
/**
* @param JsonApiSerializationVisitor $visitor
* @param Pagerfanta $pagerfanta
* @param array $type
* @param Context $context
* @return Pagerfanta
*/
public function serializePagerfanta(JsonApiSerializationVisitor $visitor, Pagerfanta $pagerfanta, array $type, Context $context)
{
$request = $this->requestStack->getCurrentRequest();
$pagerfanta->setNormalizeOutOfRangePages(true);
$pagerfanta->setAllowOutOfRangePages(true);
$pagerfanta->setMaxPerPage($request->get('page[limit]', $this->paginationOptions['limit'], true));
$pagerfanta->setCurrentPage($request->get('page[number]', 1, true));
$results = $pagerfanta->getCurrentPageResults();
if ($results instanceof \ArrayIterator) {
$results = $results->getArrayCopy();
}
$data = $context->accept($results);
$root = $visitor->getRoot();
$root['meta'] = array('page' => $pagerfanta->getCurrentPage(), 'limit' => $pagerfanta->getMaxPerPage(), 'pages' => $pagerfanta->getNbPages(), 'total' => $pagerfanta->getNbResults());
$root['links'] = array('first' => $this->getUriForPage(1), 'last' => $this->getUriForPage($pagerfanta->getNbPages()), 'prev' => $pagerfanta->hasPreviousPage() ? $this->getUriForPage($pagerfanta->getPreviousPage()) : null, 'next' => $pagerfanta->hasNextPage() ? $this->getUriForPage($pagerfanta->getNextPage()) : null);
$visitor->setRoot($root);
return $data;
}