Doctrine2 Paginator getting total results

后端 未结 2 1513
渐次进展
渐次进展 2021-01-31 18:58

Right away I would say, that I read this question Doctrine2 Paginator, but it doesn\'t give me enough information regarding the title of my question.

When I used Doctrin

相关标签:
2条回答
  • 2021-01-31 19:31

    The paginator usage is as following:

    $paginator  = new \Doctrine\ORM\Tools\Pagination\Paginator($query);
    
    $totalItems = count($paginator);
    $pagesCount = ceil($totalItems / $pageSize);
    
    // now get one page's items:
    $paginator
        ->getQuery()
        ->setFirstResult($pageSize * ($currentPage-1)) // set the offset
        ->setMaxResults($pageSize); // set the limit
    
    foreach ($paginator as $pageItem) {
        echo "<li>" . $pageItem->getName() . "</li>";
    }
    
    0 讨论(0)
  • 2021-01-31 19:41

    Or some other loop:

        for ($i=0; $i < $pagesCount; $i++) {
            if ($currentPage == ($i+1)) {
                $pagination1 .= '<li class="active"><a href="'.\URL::current().'?pagina='.($i+1).'" title="">'.($i+1).'</a></li>';
            }else{
                $pagination1 .= '<li><a href="'.\URL::current().'?pagina='.($i+1).'">'.($i+1).'</a></li>';
            }   
        }
    
    0 讨论(0)
提交回复
热议问题