2014-06-20 49 views
0

我安裝了KNP Paginator包來處理分頁。 它適用於樹枝模板,但我使用php模板。用於php模板的Symfony2 KNP PAGINATOR

這在php中有什麼相似之處?

{{ knp_pagination_render(entities) }} 

實體包含來自數據庫的數據。

回答

0
in controller: 

<?php 

$paginator = $this->get('knp_paginator'); 
$pagination = $paginator->paginate($target, $page); 
$pagination->setTemplate('MyBundle:Pagination:pagination.html.php'); 

?> 
and template: 

<?php if ($pageCount > 1): ?> 
    <div class="pagination"> 
     <?php if (isset($first) && $current != $first): ?> 
      <a href="<?php echo $view->escape($view['router']->generate($route, \array_merge($query, [$pageParameterName => $first]))); ?>">«</a> 
     <?php endif; ?> 

     <?php if (isset($previous)): ?> 
      <a href="<?php echo $view->escape($view['router']->generate($route,\array_merge($query, [$pageParameterName => $previous]))); ?>" rel="prev">‹</a> 
     <?php endif; ?> 

     <?php foreach ($pagesInRange as $page): ?> 
      <?php if ($page != $current): ?> 
       <a href="<?php echo $view->escape($view['router']->generate($route, \array_merge($query, [$pageParameterName => $page]))); ?>"><?php echo $page; ?></a> 
      <?php else: ?> 
       <?php echo $page; ?></span> 
      <?php endif; ?> 
     <?php endforeach; ?> 

     <?php if (isset($next)): ?> 
      <a href="<?php echo $view->escape($view['router']->generate($route, \array_merge($query, [$pageParameterName => $next]))); ?>" rel="next">›</a> 
     <?php endif; ?> 

     <?php if (isset($last) && $current != $last): ?> 
      <a href="<?php echo $view->escape($view['router']->generate($route, \array_merge($query, [$pageParameterName => $last]))); ?>">»</a> 
     <?php endif; ?> 
    </div> 
<?php endif; ?>