I am using the ZF1 with Zend_Paginator but if I have a search that brings all data without filter, works perfectly, but if I have a query filter paging works only on the first page.
public function getConsultaTelefones($setor)
{
if ($setor != "") {
$select = $this->select()
->setIntegrityCheck ( false )
->from ( array('t' => 'sca_telefone'))
->joinInner ( array ('p' => 'sca_posto'), 't.idPosto = p.idPosto')
->joinInner ( array ('l' => 'sca_lotacao'), 't.idLotacao = l.idLotacao')
->where("l.idLotacao = ?", $setor) ;
$resultado = $this->fetchAll($select);
} else {
$select = $this->select()
->setIntegrityCheck ( false )
->from ( array('t' => 'sca_telefone'))
->joinInner ( array ('p' => 'sca_posto'), 't.idPosto = p.idPosto')
->joinInner ( array ('l' => 'sca_lotacao'), 't.idLotacao = l.idLotacao');
$resultado = $this->fetchAll($select);
}
return $resultado;
}
In the parameter $ sector it brings all the data as the filter and creates the correct pagination, but only the first page because if I click the next or last page he "recreates" the paging all table data.
public function paginacaoConsulta($dados)
{
$pagina = intval($this->_getParam('pagina', 1));
$paginator = Zend_Paginator::factory($dados);
$paginator->setItemCountPerPage(5);
$paginator->setPageRange(7);
$paginator->setCurrentPageNumber($pagina);
$this->view->paginator = $paginator;
}
public function consultarAction()
{
$setor = $this->_getParam('setor');
$modLotacao = new Sca_Model_Lotacao('sca');
$resultado = $modLotacao->getConsultaTelefones($setor);
$this->paginacaoConsulta($resultado);
}
Already researched several things but nothing has met me. Please I need help.
Follow the rest of the codes:
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'paginacao.phtml'); ?>
<nav>
<ul class="pagination">
<li>
<!-- Link para a primeira página -->
<?php if (isset($this->previous)): ?>
<a title="Primeira Página" href="<?php echo $this->url(array('pagina' => $this->first)); ?>" aria-label="Previous">« Primeira</a>
<?php else: ?>
<a class="current" title="Primeira Página" href="<?php echo $this->url(array('pagina' => $this->first)); ?>" aria-label="Previous">« Primeira</a>
<?php endif; ?>
</li>
<li>
<?php if ($this->pageCount): ?>
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('pagina' => $this->previous)); ?>" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
<?php else: ?>
<span aria-hidden="true">«</span>
<?php endif; ?>
</li>
<li>
<?php foreach ($this->pagesInRange as $pagina): ?>
<?php if ($pagina != $this->current): ?>
<a href="<?php echo $this->url(array('pagina' => $pagina)); ?>">
<?php echo $pagina; ?>
</a>
<?php else: ?>
<a href="#"><?php echo $pagina; ?></a>
<?php endif; ?>
<?php endforeach; ?>
</li>
<li>
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('pagina' => $this->next)); ?>" aria-label="Next" >
<span aria-hidden="true">»</span>
</a>
<?php else: ?>
<span aria-hidden="true">»</span>
<?php endif; ?>
<?php endif; ?>
</li>
<li>
<!-- Última página -->
<?php if (isset($this->next)): ?>
<a title="Última Página" href="<?php echo $this->url(array('pagina' => $this->last)); ?>" aria-label="Next">Última »</a>
<?php else: ?>
<a class="current" title="Última Página" href="<?php echo $this->url(array('pagina' => $this->last)); ?>" aria-label="Next">Última »</a>
<?php endif; ?>
</li>
</ul>
</nav>
You have to pass to query param in next and previous link. Like this:
<a href="<?php echo $this->url(array('pagina' => $this->previous, 'setor' => $this->setor)); ?>" aria-label="Previous">
and pass it to the view:
$this->view->setor = $this->_getParam('setor');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.