Zend Pagination does not display values on the next page

Asked

Viewed 213 times

1

Good Afternoon.

I’m using (trying) Zend Pagination (ZF 1) but it’s 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 "submit" the form (POST method) it creates the url .. /searchdocuments/page/2 but with no 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>

inserir a descrição da imagem aqui

  • How is the route configuration of this pagination?

  • I hadn’t seen your comment, I’m sorry. I guess I don’t have routes, I didn’t necessarily see it being set up elsewhere.

2 answers

1

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

for $pager->setCurrentPageNumber($this->_getParam('page', 1));

Will work!

  • Thanks for your help, but there was no different impact. =\

  • I created a test method and another page without the subimit and works normally, but the way it is not. =\

  • shows how the pagination code was?

  • No result yet.

-1

Good evening, Voce meant that it displays the same result (same records) and any page?

It seems to be ok your code, but is it not the case that Voce take the following excerpt:

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

And in your view where

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

Place

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

What is Zend_paginator::Factory() going through? A stdClass? Does Zend treat it correctly?

Because it doesn’t try to do

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

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

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

// ...

return Zend_Paginator::factory($sql);

This way improves even the performance, because the database is who makes the pagination, He drew? ;)

I hope I helped, hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.