stackUnderflow February 2016

Zend paginator - is it possible to set custom params?

I am taking care of a legacy Zend project. There is a table which is populated with some values using Paginator:

paginator = Zend_Paginator::factory( $this->_getRecords($filter1, $filter2)   );

$paginator->setCurrentPageNumber($this->_getParam('page'));
$this->view->paginator = $paginator;

Now here is the issue. This paginator does not know the filters ( filter1 and filter2 ).

Clicking on some page results in empty filter1 and filter2 values. What I want to do is to set those filters as params in the paginator, smthing like:

/admin/users/index/page/7/filter1/value1/filter2/value2

Then to be able to say:

paginator = Zend_Paginator::factory( $this->_getRecords($this->_getParam('filter1'), $this->_getParam('filter2'))   );

Is this possible ?

Answers


Max P. February 2016

Paginator doesn't generate urls. Urls are generated by router.

Transmit filters to template for current page

$this->view->paginator = $paginator;
$this->view->filters = array('filter1'=>$filter1, 'filter2'=>$filter2);

In template for current page transmit filters to paginator template

<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.tpl', array('filters'=>$this->filters)); ?>

In paginator template 'pagination.tpl' add them to url generation function

<a href="<?php echo $this->url($this->filters + array('page'=>($this->current-1))); ?>">prev</a>

<a href="<?php echo $this->url($this->filters + array('page'=>($this->current+1))); ?>">next</a>

Post Status

Asked in February 2016
Viewed 3,962 times
Voted 6
Answered 1 times

Search




Leave an answer