Symfony2 KNP PAGINATOR for php template



我安装了KNP Paginator包来处理分页。它与小枝模板,但我的工作与php模板。

在php中类似的是什么?

{{ knp_pagination_render(entities) }}

实体包含来自数据库的数据

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; ?>

相关内容

  • 没有找到相关文章

最新更新