[英]php pagination hide previous and next button using symfony framework
嗨,我使用symfony框架进行了分页,我想知道如果页面已经在首页中,那么该按钮如何隐藏,因此没有上一个按钮,如果最后一页没有下一个按钮。
我将如何获得currentPage?
这是我的代码:
<?php if ($pager->haveToPaginate()) :?>
<div class="pagerWrapper ">
<nav>
<ul class="pager">
<?php if($currPage != 1):?>
<li class="pageNumber"><?php echo link_to('<img alt="Previous Page" src="/images/pager_prev_btn.png" class="page_img" />', url_for('contract/index?page='.$pager->getPreviousPage()), 'class=""' )?></li>
<?php endif;?>
<?php foreach ($pager->getLinks() as $page) :?>
<li class="pageNumber"><?php echo link_to($page, url_for('contract/index?page='.$page), ($page == $pager->getPage()) ?'class="selected"' : 'class=""')?></li>
<?php endforeach;?>
<?php if($pager->getLastPage() != $currPage): ?>
<li class="pageNumber"><?php echo link_to('<img alt="Next Page" src="/images/pager_next_btn.png" class="page_img" />', url_for('contract/index?page='.$pager->getNextPage()),'class=""')?></li>
<?php endif; ?>
</ul>
</nav>
</div>
<?php endif;?>
这是我的控制器
public function executeIndex(sfWebRequest $request){
$currPage = $request->getParameter('page', 1);
$limit = sfConfig::get('app_contract_list_limit');
$offset = ($currPage - 1) * $limit;
$q = ContractTable::getInstance()->getContractList($offset,$limit);
$this->contractList = $q->execute();
$this->pager = new sfDoctrinePager('Contract', $limit);
$this->pager->setQuery($q);
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
}
请帮助我感到困惑,谢谢
您可以使用$pager->getPage()
获取当前页面, $pager->getPage()
: http : $pager->getPage()
对于第一页和最后一页,您可以使用类似以下内容:
if (!$pager->isFirstPage())
{
}
foreach ($pager->getLinks() as $page)
{
}
if (!$pager->isLastPage())
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.