Zend Pagination does not display values on the next page

1

Good afternoon.

I am using (trying) Zend Pagination (ZF 1) but it is not displaying the rest of the result on the next page.

I have the following method:

 public function pesquisadocumentosAction()
    {
        if(!empty($_POST)) {
            $situacao   = $this->_getParam('situacao');
            $dtInicial  = $this->_getParam('dataInicial');
            $dtFinal    = $this->_getParam('dataFinal');
            $codGetran  = $this->_getParam('codGetran');


            if (empty($situacao) and empty($dtInicial) and empty($dtFinal) and empty($codGetran)) {

                $modDocumento = new Sisgeof_Model_DocRecebido('sisgeof');
                $filtro = $modDocumento->getAll();

                $pagina = $this->_getParam('pagina', 1);

                $paginador = Zend_Paginator::factory($filtro);
                $paginador->setItemCountPerPage(5);
                $paginador->setPageRange(9);
                $paginador->setCurrentPageNumber($this->_getParam('pagina', 1));

                Zend_Paginator::setDefaultScrollingStyle('Sliding');
                Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
                $this->view->assign('paginador', $paginador);

            } 

Pagination.phtml

<?php if ($this->pageCount): ?>
    <nav>
        <ul class="pagination">
            <li>
                <?php if (isset($this->previous)): ?>
                    <a href="<?php echo $this->url(array('pagina' => $this->previous)); ?>" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                <?php else: ?>
                    <span aria-hidden="true">&laquo;</span>
                <?php endif; ?>
            </li>


            <li>
            <?php foreach ($this->pagesInRange as $page): ?>
                <?php if ($page != $this->current): ?>
                        <a href="<?php echo $this->url(array('pagina' => $page)); ?>">
                            <span aria-hidden="true"><?php echo $page; ?></span>
                        </a>
                <?php else: ?>
                    <span aria-hidden="true"><?php echo $page; ?></span>
                <?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">&raquo;</span>
                    </a>
                <?php else: ?>
                    <span aria-hidden="true">&raquo;</span>
                <?php endif; ?>
            </li>
    </nav>
<?php endif; ?>

When you submit the form (POST method) it creates the url ../search/page/2 but without result.

What's going on?

Form Code:

<form action="<?php echo $sig_url ?>sisgeof/documento/pesquisadocumentos" method="post" name="pesquisaDocumentos" id="formular">
        <div class="row">
            <div class="col-md-2 col-md-offset-2">
                Prazo do Documento:
                <select class="form-control" name="situacao">
                    <option value=""></option>
                    <option value="1">Maior que 6 dias</option>
                    <option value="2">Entre 3 e 5 dias</option>
                    <option value="3">Menor que 3 dias</option>
                </select>
            </div>

            <div class="col-md-2">
                Data Inicial:
                <input type="text" class="form-control" name="dataInicial" id="dataInicial" placeholder="__/__/____" maxlength="10">
            </div>

            <div class="col-md-2">
                Data Final:
                <input type="text" class="form-control" name="dataFinal" id="dataFinal" placeholder="__/__/____" maxlength="10">
            </div>

            <div class="col-md-2">
                Código Getran:
                <input type="text" class="form-control" name="codGetran" id="codGetran" maxlength="6">
            </div>
        </div>
        <br/>
        <div class="row">
            <div class="col-md-5 col-md-offset-5">
                <button type="submit" class="btn btn-default">Pesquisar</button>
            </div>
        </div>
    </form>
    <br/>
    <!-- Div que exibe os resultados da pesquisa -->
    <?php
        if(!empty($_POST)) {
            if($this->paginador == false){
                echo $this->noResult;
                echo $this->dataInvalida;
            } else {
    ?>
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <table class="table">
                <tr class="active">
                    <td><strong>Cod. Getran</strong></td>
                    <td><strong>Origem</strong></td>
                    <td><strong>Número do Doc.</strong></td>
                    <td><strong>Ano</strong></td>
                    <td><strong>Matrícula</strong></td>
                    <td class="text-center"><strong>Visualizar</strong></td>
                </tr>
                <?php
                    foreach($this->paginador as $dado) :
                ?>
                    <tr class="mouseOn">
                        <td><?php echo $dado->cd_getran; ?></td>
                        <td><?php echo $dado->origem; ?></td>
                        <td><?php echo $dado->numero_doc; ?></td>
                        <td><?php echo $dado->ano; ?></td>
                        <td><?php echo $dado->cd_matricula; ?></td>
                        <td class="text-center">
                            <a href="<?php echo $sig_url ?>sisgeof/documento/editadocumento?idDoc=<?php echo $dado->id_doc_recebido; ?>"
                               name="editarDocumento"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></a>
                        </td>
                    </tr>
                <?php
                    endforeach;
                ?>
            </table>
        </div>
    </div>
    <?php
         } }
    ?>
    <div class="row">
        <div class="col-md-3 col-md-offset-5">
            <!-- paginador -->
            <?php echo $this->paginador; ?>
        </div>
    </div>

    
asked by anonymous 06.01.2015 / 19:17

2 answers

1

Change line $ pager -> setCurrentPageNumber ($ page);

by $ paginator-> setCurrentPageNumber ($ this-> _getParam ('page', 1));

It will work!

    
07.01.2015 / 20:28
-1

Good evening, did you mean that it displays the same result (same records) and any page?

Your code seems okay, but is not it the case that you take the following snippet:

Zend_Paginator::setDefaultScrollingStyle('Sliding');
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');

And in your view where you have

<?php echo $this->paginador; ?>

Place

<?php echo $this->paginationControl($this->paginador, 'Sliding', 'pagination.phtml'); ?>

What are you doing in the Zend_Paginator :: factory () method? A stdClass? Does Zend handle this correctly?

Why do not you try

Zend_Paginator::factory((array) $filtro);

A very effective practice I used to use with Zend 1 is paging the query output in the model

$sql = $this->_db->select(); // Aqui segue a query normalmente

// ...

return Zend_Paginator::factory($sql);

In this way it improves to performance, because the database is the one that does the pagination, right? ;)

I hope to have helped, hug.

    
11.01.2015 / 02:31