Search code examples
zend-frameworkzend-paginator

Zend_Paginator links with query params


Could you please tell me how to make link with Zend_Paginator like this: http://url/controller/action?id=47&page=2. I want to add to url additional paramter to the query of url like url?id=value, not paramater like this one: url/controller/action/param/value. Could you also tell please how to pass a variable for view to partial aside from page. Thank you.


Solution

  • There is the default view helper Url that is made for handling that.

    you can generate your url with the following :

    echo $this->url(array('controller' => 'controllerName',
                          'action'     => 'actionName',
                          'param1'     => 'param1',
                          'param2'     => 'param2));
    

    If you omit some of the params, the helper will reuse those that were in the query url

    So, with Zend_Paginator you go this way :

    $pages = $this->paginator->getPages();
    
    // previous
    echo $this->url(array('page' => ($pages->current -1)));
    
    // current
    echo $this->url(array('page' => ($pages->current)));
    
    // next
    echo $this->url(array('page' => ($pages->current +1)));
    

    ** EDIT **

    Exemple to reflect my first comment

    echo $this->url(array('controller' => 'controllerName', 'action' => 'actionName')) . '?user=' . $id . '&page=' . $pageNumber