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

Get language parameter inside Zend Paginator ahref urls (clickable links)

这是我在 index.phtml viewscript 中的当前代码:

<?= $this->paginationControl($posts,'Sliding','application/partial/paginator', ['route' => 'home','lang'=>'it']); ?>

我想在此 paginationControl 调用中传递 :lang 参数,以便通知路由器并且 html 结果显示内部的 it lang pagination html ahref code for clickable links.

我不太确定如何正确执行此操作。

这是我的路线:

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

此分页器的结果 html 将显示:

/pp/public/it?page=2

但目前显示

/pp/public/en?page=2

即使我在意大利语版页面上也是如此

嗯,这取决于您如何设置 paginationControl 部分或 viewpage 脚本。

paginationControl参数:

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

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

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

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

所以现在在您的分页部分中您可以使用路由、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; ?>