【问题标题】:Pagerfanta symfony PaginationPagerfanta symfony 分页
【发布时间】:2016-07-22 23:48:04
【问题描述】:

我有一个 mysql 数据库博客,里面有 21 个帖子。 我设置 $maxPerPage = '3';所以我得到了 7 页,但从第 4 页开始出现以下错误:

OutOfRangeCurrentPageException:页面“4”不存在。 currentPage 必须小于“3”

这是我的代码:

  public function indexAction($page)

{

$maxPerPage = '3';
$currentPage = $page;

$entityManager = $this->getDoctrine()->getManager();
$queryBuilder = $entityManager->createQueryBuilder()
->select(array('u')) // string 'u' is converted to array internally
->from('AppBundle:Blog', 'u');
$adapter = new DoctrineORMAdapter($queryBuilder);
$pagerfanta = new Pagerfanta($adapter);
if (!$page) $currentPage = '1';
try  {
    $pagerfanta->setCurrentPage($currentPage);
}
catch(NotValidCurrentPageException $e) {
  throw new NotFoundHttpException('Illegal page');
}
$pagerfanta->setMaxPerPage($maxPerPage); // 10 by default






//$textblog = $this->getDoctrine()
  //->getRepository('AppBundle:Blog')
  //->find($page);


return $this->render('textblog/blog.html.twig',array('pagerfanta' => $pagerfanta));

}

有人可以帮忙吗?

【问题讨论】:

    标签: symfony pagerfanta


    【解决方案1】:

    愚蠢的我......

    $pagerfanta->setMaxPerPage($maxPerPage);
    

    这段代码应该在'if'之前

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      • 2016-05-31
      • 2015-10-25
      相关资源
      最近更新 更多