本文整理汇总了PHP中Pagerfanta\Pagerfanta::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Pagerfanta::count方法的具体用法?PHP Pagerfanta::count怎么用?PHP Pagerfanta::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pagerfanta\Pagerfanta
的用法示例。
在下文中一共展示了Pagerfanta::count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPagerfantaRepresentation
/**
* Construct a pagerfanta representation from the current request
*
* @param AdapterInterface $adapter - The adapter to use
* @return QueryablePaginatedRepresentation
*/
protected function getPagerfantaRepresentation(Request $request, AdapterInterface $adapter)
{
$pagerfanta = new Pagerfanta($adapter);
$limit = $request->query->get('limit');
$zeroLimit = false;
if (!$limit && ($limit === 0 || $limit === '0')) {
$limit = $pagerfanta->count();
$zeroLimit = true;
}
if (!$limit) {
$limit = 10;
}
$pagerfanta->setMaxPerPage($limit);
$page = $request->query->get('page');
$nbPages = $pagerfanta->getNbPages();
if (!$page) {
$page = 1;
}
// Avoid errors: redirect to max page
if ($page > $nbPages) {
$page = $nbPages;
}
$pagerfanta->setCurrentPage($page);
$route = new Route($request->get('_route'), $request->attributes->get('_route_params'), false);
return new QueryablePaginatedRepresentation(new CollectionRepresentation($pagerfanta->getCurrentPageResults()), $route->getName(), $route->getParameters(), $pagerfanta->getCurrentPage(), $zeroLimit ? 0 : $pagerfanta->getMaxPerPage(), $nbPages, $pagerfanta->count(), null, null, $route->isAbsolute(), $request->query->get('where'), $request->query->get('search'), $request->query->get('order'), null, null, null);
}
示例2: paginate
/**
* @param Request $request
* @param AdapterInterface $adapter
* @param string|null $route
*
* @return PaginatedRepresentation
*/
protected function paginate(Request $request, AdapterInterface $adapter, $route = null, $routeParameters = null)
{
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($request->query->get(self::LIMIT_PARAMETER, 5));
$pagerfanta->setCurrentPage($request->query->get(self::PAGE_PARAMETER, 1));
$collection = new CollectionRepresentation($pagerfanta->getCurrentPageResults());
$paginated = new PaginatedRepresentation($collection, $route ?? $request->get('_route'), $routeParameters ?? $request->attributes->get('_route_params'), $pagerfanta->getCurrentPage(), $pagerfanta->getMaxPerPage(), $pagerfanta->getNbPages(), self::PAGE_PARAMETER, self::LIMIT_PARAMETER, false, $pagerfanta->count());
return $paginated;
}
示例3: serializePagerfantaToJson
public function serializePagerfantaToJson(JsonSerializationVisitor $visitor, Pagerfanta $pagerfanta, array $type, Context $context)
{
$type['name'] = 'array';
return ['items' => $visitor->visitArray((array) $pagerfanta->getCurrentPageResults(), $type, $context), 'pages_count' => $pagerfanta->getNbPages(), 'current_page' => $pagerfanta->getCurrentPage(), 'max_per_page' => $pagerfanta->getMaxPerPage(), 'items_count' => $pagerfanta->count()];
}
示例4: getTotal
/**
* Get the total number of results.
*
* @return int
*/
public function getTotal() : int
{
return $this->paginator->count();
}
示例5: testCountShouldReturnNbResults
public function testCountShouldReturnNbResults()
{
$this->setAdapterNbResultsAny(30);
$this->assertSame(30, $this->pagerfanta->count());
}