在Zend Paginator ahref urls中获取语言参数(可点击链接)

时间:2016-12-27 23:52:52

标签: php pagination zend-framework2

以下是[self.session startRunning]; // wait 15 seconds dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 15 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [self.session stopRunning]; }); 视图中的当前代码:

index.phtml

我想在此<?= $this->paginationControl($posts,'Sliding','application/partial/paginator', ['route' => 'home','lang'=>'it']); ?> 来电中传递:lang参数,以便通知路由器并且html结果会在paginationControl内显示it lang

我不太确定如何正确地做到这一点。

这是我的路线:

pagination html ahref code for clickable links

此分页器生成的html将显示:

'home' => [ 'type' => Segment::class, 'options' => [ 'route' => '/:lang', 'defaults' => [ 'controller' => ApplicationIndexController::class, 'action' => 'index', 'lang' => 'en' ], ], ],

但它目前显示

/pp/public/it?page=2

即使我在页面的意大利语版本上

1 个答案:

答案 0 :(得分:0)

这取决于你如何设置paginationControl部分或浏览页面脚本。

paginationControl参数:

PaginationControl::__invoke(Paginator $myPaginator, $scrollingStyle, $partial, $params);

因此,在分页的部分或查看页面脚本中,您可以访问传递给$params参数的所有内容,就像您从控制器传递到视图页面或部分参数一样视图助手。

您可以将参数传递给部分,例如要使用的路径及其路径和查询参数。

$this->paginationControl(
    $posts,
    'sliding',
    'application/partial/pagination',
    [
        'route' => 'home',
        'routeParams' => ['lang' => 'it'], 
        'queryParams' => []
    ]
);

所以现在在你的分页部分你可以使用route,routeParams和queryParams - Template used - Item pagination

<?php
if (!isset($queryParams)) {
    $queryParams = [];
}
if (!isset($routeParams)) {
    $routeParams = [];
}
?>

<?php if ($this->pageCount): ?>
<div class="paginationControl">
    <?= $this->firstItemNumber; ?> - <?= $this->lastItemNumber; ?>
    <?= $this->translate('of'); ?> <?= $this->totalItemCount; ?>

    <!-- First page link -->
    <?php if (isset($this->previous)): ?>
        <a href="<?= $this->url(
            $this->route,
            $routeParams,
            ArrayUtils::merge($queryParams, ['query' => ['page' => $this->first]])
        ); ?>">
            <?= $this->translate('First'); ?>
        </a> |
    <?php else: ?>
        <span class="disabled"><?= $this->translate('First') ?></span> |
    <?php endif; ?>

    <!-- Previous page link -->
    <?php if (isset($this->previous)): ?>
        <a href="<?= $this->url(
            $this->route,
            $queryParams,
            ArrayUtils::merge($queryParams, ['query' => ['page' => $this->previous]])
        ); ?>">
            &lt; <?= $this->translate('Previous') ?>
        </a> |
    <?php else: ?>
        <span class="disabled">&lt; <?= $this->translate('Previous') ?></span> |
    <?php endif; ?>

    <!-- Next page link -->
    <?php if (isset($this->next)): ?>
        <a href="<?= $this->url(
            $this->route,
            $routeParams,
            ArrayUtils::merge($queryParams, ['query' => ['page' => $this->next]])
        ); ?>">
            <?= $this->translate('Next') ?> &gt;
        </a> |
    <?php else: ?>
        <span class="disabled"><?= $this->translate('Next') ?> &gt;</span> |
    <?php endif; ?>

    <!-- Last page link -->
    <?php if (isset($this->next)): ?>
        <a href="<?= $this->url(
            $this->route,
            $routeParams,
            ArrayUtils::merge($queryParams, ['query' => ['page' => $this->last]])
        ); ?>">
            <?= $this->translate('Last') ?>
        </a>
    <?php else: ?>
        <span class="disabled"><?= $this->translate('Last') ?></span>
    <?php endif; ?>