I installed the KNP Paginator bundle to handle pagination. It works with the twig template but I work with a php template.
What is similar to this in php ?
{{ knp_pagination_render(entities) }}
Entities contains data from a database.
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; ?>