-1
我有一个mysql数据库博客,其中有21篇文章。 我设置了$ maxPerPage ='3';所以我得到7页,但从页4我得到以下错误:Pagerfanta symfony分页
OutOfRangeCurrentPageException:页面“4”不存在。该当前是要逊色于 “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));
}
谁能帮助吗?