Zend_session and Zend_pagination with search form

Asked

Viewed 188 times

0

I have problems in a pagination with searching via form in Zend Framework 1.

There is a method in the model that makes a query with Where to bring the result as the search done, and the pagination if it is done without session works only the first page, because the others do not bring the results as filter.

After days of searching and still no solution, I saw that I can really try to use the session to try to remedy this problem, but I don’t understand how to apply this.

I have the following controller:

public function consultarAction()
    {

        $setor = $this->_getParam('setor');

        $modLotacao = new Sca_Model_Lotacao('sca');

        $resultado = $modLotacao->getConsultaTelefones($setor);

        $busca = new Zend_Session_Namespace($resultado);

        if ($this->_request->isPost()) {
            $busca->unsetAll();
            $busca->busca = $this->_request->getPost();
        }

        $paginator = Zend_Paginator::factory($resultado($busca->busca));
        $paginator->setItemCountPerPage(5);
        $paginator->setPageRange(7);
        $paginator->setCurrentPageNumber(intval($this->_request->getParam('pagina', 1)));

        $this->view->paginator = $paginator;    

    }

This is returning me error, but really must be something wrong that I do not know =\

Anyway, could someone help me?

1 answer

1


I have already solved this problem of filters in paging without Session, just passing parameters. Follows the solution:

Controller

Get the list and assemble the Paginator:

$paginator = Zend_Paginator::factory($lista);
$paginator->setItemCountPerPage(12)->setCurrentPageNumber($this->getParam('p', 1));
$paginator->setPageRange(5);
$this->view->assign('lista', $paginator);

Send the search to view also:

$this->view->assign('busca', $this->getParam('busca'));

View of action

Print the layout of the pagination, passing the search in the 4th parameter:

echo $this->paginationControl($this->lista, 'Sliding', 'pagination.phtml', array('busca' => $this->busca));

View of the pagination

In the view of paging (normally pagination.phtml), receives the parameter with filters:

$filtros = $this->busca

...and concatenates them to us links of pagination.

  • I really handled it with Session, but it’s good this one of yours, and who knows who now will get easier one day. Because it was very difficult to find any practical solution to this. Thank you!

  • I had some problems with the use of the session... because when I delete the record it is not disappearing, until pq to using the forward as I posted another link there. @Lucas did not understand this application of yours without.

  • I didn’t understand this application on top of what I did, you still used the $session search?

  • 1

    No. The search comes by parameter (GET or POST), using getParam(). Then send this search to view (assign) and pass it by parameter to the script of pagination.

  • Malz, but I’m not getting it right. =\

  • Your search comes for GET? You have a pagination.phtml?

  • Via POST and yes I have pagination.phtml -- <? php if (isset($this->next)): ? > <a href="<? php echo $this->url(array('page' => $this->next)); ? >" Aria-label="Next" > <span Aria-Hidden="true">&raquo;</span> </a>

  • Then, go through parts as I wrote in the reply, going from one script to the other, until you receive there in pagination.phtml and concatenate in the link

Show 4 more comments

Browser other questions tagged

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