dongzhong7443 2016-12-27 23:52
浏览 15
已采纳

too long

Here's my current code within an index.phtml viewscript:

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

I'd like to pass the :lang parameter within this paginationControl call so that way the router is notified and the html results show the it lang inside the pagination html ahref code for clickable links.

I'm not quite sure how to correctly do this.

Here's my route:

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

The resulting html from this paginator will show:

/pp/public/it?page=2

But it currently shows

/pp/public/en?page=2

even when im on the italian version of the page

  • 写回答

1条回答 默认 最新

  • doubengshao8872 2016-12-28 10:21
    关注

    Well it depends on how you setup your paginationControl partial or viewpage script.

    The paginationControl parameters:

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

    So within your partial or viewpage script for the pagination you are able to access all the stuff you passed to the $params parameter, like you would with your parameters you pass from your controller to your view pages or the partial viewhelper.

    You could pass a parameter to the partial like the route to use and its route and query parameters.

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

    So now within your pagination partial you could use the route, routeParams and 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; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch