Hi, I have this pagination using the symfony framework, I'm wondering how to hide the button if the page is already in first page, so no previous button, and if last page no next button.
How will I able to get the currentPage?
Here's my code:
<?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;?>
heres my controller
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();
}
please help I'm confused, thanks
You can get the current page with
$pager->getPage()
According to : http://propelorm.org/reference/model-criteria.html#paginating-resultsAnd for first and last page you can use something like that :