我使用KnpPaginatorBundle。通常我在symfony2.3中使用php-templates。有没有办法使用php-templates为KnpPaginatorBundle分页?我找不到任何教程或任何文档。
感谢。
更新 如何在php模板中呈现这个?
{# total items count #}
<div class="count">
{{ pagination.getTotalItemCount }}
</div>
<table>
<tr>
{# sorting of properties based on query components #}
<th>{{ knp_pagination_sortable(pagination, 'Id', 'a.id') }}</th>
<th{% if pagination.isSorted('a.Title') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'Title', 'a.title') }}</th>
</tr>
{# table body #}
{% for article in pagination %}
<tr {% if loop.index is odd %}class="color"{% endif %}>
<td>{{ article.id }}</td>
</tr>
{% endfor %}
</table>
{# display navigation #}
<div class="navigation">
{{ knp_pagination_render(pagination) }}
</div>
答案 0 :(得分:2)
是的,在配置中有一种方法:
knp_paginator.template.pagination: MyBundle:Pagination:pagination.html.php
或直接在控制器中:
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate($target, $page);
$pagination->setTemplate('MyBundle:Pagination:pagination.html.php');
DOCS: https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/templates.md
答案 1 :(得分:2)
分页模板的PHP版本:
<?php #total items count ?>
<div class="count">
<?php echo $pagination->getTotalItemCount(); ?>
</div>
<table>
<tr>
<?php # sorting of properties based on query components ?>
<th <?php echo $view['knp_pagination']->sortable($pagination, 'Id', 'a.id') ?></th>
<th<?php if ($pagination->isSorted('a.Title')){echo ' class="sorted"';}?>><?php echo $view['knp_pagination']->sortable($pagination, 'Title', 'a.title') ?></th>
</tr>
<?php # table body ?>
<?php foreach ($pagination as $key => $article): ?>
<tr <?php if ($key %2 == 0){echo 'class="color"';}?>>
<td><?php echo $article->getId() ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php # display navigation ?>
<div class="navigation">
<?php echo $view['knp_pagination']->render($pagination) ?>
</div>
答案 2 :(得分:0)
另外,您可以尝试模板方式:
{{ knp_pagination_render(content, 'MyBundle:ContentNew/Pagination:sliding.html.twig') }}