Sha*_*lav 5 php pagination zend-framework2
我正在尝试在我的新闻源上创建分页.我的新闻Feed中有两种模式:所有新闻Feed和按类别提供的Feed.所有新闻Feed的分页工作正常,但我有"按类别分类"分页的问题.
我像这样使用paginationControl:
<?=$this->paginationControl(
$this->news,
'Sliding',
'pagination_control',
array('route' => 'news/category')
)?>
Run Code Online (Sandbox Code Playgroud)
路线news/category配置:
'category' => array(
'type' => 'Segment',
'options' => array(
'route' => '/:category[/page-:page]',
'constraints' => array(
'category' => '[a-z]+',
'page' => '[1-9][0-9]*',
),
'defaults' => array(
'controller' => 'News\Controller\Item',
'action' => 'category',
'page' => 1,
)
),
'may_terminate' => true,
),
Run Code Online (Sandbox Code Playgroud)
所以我需要指定参数类别.我在尝试这个:
<?=$this->paginationControl(
$this->news,
'Sliding',
'pagination_control',
array('route' => 'news/category', array('category' => $this->category->getUrl()))
)?>
Run Code Online (Sandbox Code Playgroud)
但我收到错误"缺少参数...":
看起来无法通过paginationControl设置参数.
如何在paginationControl中正确指定带参数的路由?
我的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))?>">
«
</a>
</li>
<? else: ?>
<li class="disabled"><span>«</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))?>">
»
</a>
</li>
<?php else: ?>
<li class="disabled"><span>»</span></li>
<?php endif; ?>
</ul>
</div>
<div>
<span class="small grey"><?="???????? ".$this->current." ?? ".$this->pageCount?></span>
</div>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)
您应该将所有其他参数作为关联数组传递到最后,如@ rianattow所说.通过这种方式,您可以在pagination_control.phtml部分通道中访问所有参数$this->paramname
例:
echo $this->paginationControl(
$this->news,
'Sliding',
'pagination_control',
array( 'route' => 'news/category', 'category' => 'banana')
);
Run Code Online (Sandbox Code Playgroud)
在paginator文档中说明了这个细节:
第四个也是最后一个参数是为您希望在视图中可用的其他变量的可选关联数组保留的(可通过$ this获得).例如,这些值可能包括分页链接的额外URL参数.
我认为其他缺点是使用路由名称构建URL.不要将url paginationControl()作为参数传递给帮助器,而是尝试在分页部分内生成url,如下所示:
<a href="<?
echo $this->url($this->route, array('page' => $page, 'category' => $this->category))
?>">
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
1717 次 |
| 最近记录: |