Php 如何在paginationControl中使用参数指定路由?

Php 如何在paginationControl中使用参数指定路由?,php,pagination,zend-framework2,Php,Pagination,Zend Framework2,我正在尝试在我的新闻提要上创建分页。我的新闻提要有两种模式:所有新闻提要和按类别提要。所有新闻提要的分页都很好,但我对“按类别提要”分页有问题 我使用的分页控件如下所示: <?=$this->paginationControl( $this->news, 'Sliding', 'pagination_control', array('route' => 'news/category') )?> <a href="<?

我正在尝试在我的新闻提要上创建分页。我的新闻提要有两种模式:所有新闻提要和按类别提要。所有新闻提要的分页都很好,但我对“按类别提要”分页有问题

我使用的分页控件如下所示:

<?=$this->paginationControl(
    $this->news,
    'Sliding',
    'pagination_control',
    array('route' => 'news/category')
)?>
<a href="<?
    echo $this->url($this->route, array('page' => $page, 'category' => $this->category))
?>">
所以我需要指定参数类别。我正在尝试:

<?=$this->paginationControl(                                                                 
    $this->news,                                                                             
    'Sliding',                                                                               
    'pagination_control',                                                                    
    array('route' => 'news/category', array('category' => $this->category->getUrl()))        
)?>          

但我得到错误“缺少参数…”:

看起来无法通过paginationControl设置参数

如何使用paginationControl中的参数正确指定路由

更新1 我的paginationControl视图如下所示:

<?php if ($this->pageCount > 1): ?>
    <div>
        <ul class="pagination pagination-sm">
            <!-- Previous page link -->
            <?php if (isset($this->previous)): ?>
                <li>
                    <a href="<?=$this->url($this->route, array('page' => $this->previous))?>">
                        &laquo;
                    </a>
                </li>
            <? else: ?>
                <li class="disabled"><span>&laquo;</span></li>
            <? endif; ?>

            <!-- Numbered page links -->
            <? foreach ($this->pagesInRange as $page): ?>
                <? if ($page != $this->current): ?>
                    <li>
                        <a href="<?=$this->url($this->route, array('page' => $page))?>">
                            <?=$page?>
                        </a>
                    </li>
                <? else: ?>
                    <li class="active"><span><?=$page?></span></li>
                <? endif; ?>
            <? endforeach; ?>

            <!-- Next page link -->
            <?php if (isset($this->next)): ?>
                <li>
                    <a href="<?=$this->url($this->route, array('page' => $this->next))?>">
                        &raquo;
                    </a>
                </li>
            <?php else: ?>
                <li class="disabled"><span>&raquo;</span></li>
            <?php endif; ?>
        </ul>
    </div>
    <div>
        <span class="small grey"><?="Страница ".$this->current." из ".$this->pageCount?></span>
    </div>
<?php endif; ?>

  • «
  • »

您应该像@rianattow所说的那样,在末尾以关联数组的形式传递所有附加参数。这样,所有这些参数都可以通过
$this->paramname

例如:

echo $this->paginationControl(                                                                 
     $this->news,                                                                             
     'Sliding',                                                                               
     'pagination_control',                                                                    
     array( 'route' => 'news/category', 'category' => 'banana')
    );
该细节在以下文件中说明:

第四个也是最后一个参数是为可选的关联参数保留的 希望在视图中可用的附加变量数组 (可通过$this获得)。例如,这些值可以包括额外的 分页链接的URL参数

我认为另一个缺失点是使用路由名称构建URL。不要将url作为参数传递给
paginationControl()
helper,而是尝试在分页部分中生成url,如下所示:

<?=$this->paginationControl(
    $this->news,
    'Sliding',
    'pagination_control',
    array('route' => 'news/category')
)?>
<a href="<?
    echo $this->url($this->route, array('page' => $page, 'category' => $this->category))
?>">

在同一级别上设置其他参数时会发生什么?例如,
array('route'=>'news/category','category'=>$getUrl())
@raina77ow什么都没有:(相同的结果:(你的部分phtml看起来像什么?@BramGerritsen我更新了我的答案并添加了部分html代码。工作解决方案有点不同,但你给了我一个想法。我更新了你的答案。非常感谢。完美。