我正在尝试使用 Pagerfanta 对结果进行分页
我的控制器:
/**
* @Rest\Get(
* path="/users",
* name="get_users",
* )
*
* @return View
*/
public function users()
{
$pagers = $this->getDoctrine()->getManager()->getRepository(User::class)
->findAllWithPagination(10, 1);
return $this->view($pagers->getCurrentPageResults(), Response::HTTP_OK);
}
我的用户存储库:
/**
* @param int $limit
* @param int $offset
* @return Pagerfanta
*/
public function findAllWithPagination(int $limit = 10, int $offset = 1): Pagerfanta
{
$qb = $this->createQueryBuilder('u')
->select('u')
;
return $this->paginate($qb, $limit, $offset);
}
/**
* @param QueryBuilder $qb
* @param int $limit
* @param int $offset
* @return Pagerfanta
*/
protected function paginate(QueryBuilder $qb, int $limit = 10, int $offset = 1): Pagerfanta
{
if (0 == $limit || 0 == $offset) {
throw new \LogicException('$limit & $offset must be greater than 0.');
}
$pager = new Pagerfanta(new DoctrineORMAdapter($qb));
$currentPage = ceil($offset + 1) / $limit;
$pager->setCurrentPage($currentPage);
$pager->setMaxPerPage($limit);
return $pager;
}
我不明白为什么我在尝试访问此资源时会收到 404 响应。我做错了什么?
“消息”:“找不到页面”,“类”:“Symfony\Component\HttpKernel\Exception\NotFoundHttpException”,“文件”:“/var/www/html/model-backend/vendor/white-october/pagerfanta- bundle/EventListener/ConvertNotValidCurrentPageToNotFoundListener.php",