我安装了KNP Paginator包来处理分页。 它适用于twig模板,但我使用的是php模板。
在php中有什么类似的东西?
{{ knp_pagination_render(entities) }}
实体包含数据库中的数据。
答案 0 :(得分: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; ?>