0

我安装了 KNP Paginator 包来处理分页。它适用于 twig 模板,但我使用的是 php 模板。

php 中有什么类似的东西?

{{ knp_pagination_render(entities) }}

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

4

1 回答 1

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">‹&lt;/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">›&lt;/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; ?>
于 2014-09-08T21:23:25.477 回答