title: ZF2 - Retain query from form using url helper in pagination
body: <p>I'm new to ZF2 and I'm willing to share how I do to retain parameter from form using url helper especially during pagination. I modify the answer from <a href="https://stackoverflow.com/questions/12785190/how-can-you-add-query-parameters-in-the-zf2-url-view-helper">How can you add query parameters in the ZF2 url view helper</a></p>
  
  <p>This is what I do:</p>
  
  <p><strong>AlbumController.php</strong></p>
  
  <pre><code>// get all the query from url
  $input = $form-&gt;getData();
  
  $paginator = $this-&gt;getAlbumTable()-&gt;fetchAll();
  $paginator-&gt;setCurrentPageNumber((int)$this-&gt;params()-&gt;fromQuery('page', 1));
  $paginator-&gt;setItemCountPerPage(30);
  
  // unset the 'page' query if necessary
  unset($input['page']);
  
  return array(
      'form'   =&gt; $form,
      'paginator' =&gt; $paginator,
      'routeParams' =&gt; array_filter($input) // filter empty value
  );
  </code></pre>
  
  <p><strong>index.phtml</strong></p>
  
  <pre><code>echo $this-&gt;paginationControl(
      $this-&gt;paginator,
      'sliding',
      array('partial/paginator.phtml', 'Album'),
      array(
          'route' =&gt; 'album',
          'routeParams' =&gt; $routeParams
      )
  );
  </code></pre>
  
  <p><strong>paginator.phtml</strong></p>
  
  <pre><code>&lt;a href="&lt;?php echo $this-&gt;url(
                      $this-&gt;route, // your route name
                      array(),      // any url options, e.g action
                      array('query' =&gt; $this-&gt;routeParams) // your query params
                 ); 
  echo (empty($this-&gt;routeParams))?  '?' : '&amp;'; ?&gt;
  page=&lt;?php echo $this-&gt;next; ?&gt;"&gt;Next Page&lt;/a&gt;
  </code></pre>
  
  <p>Please provide any better solution and correct me if I'm wrong.</p>
  
  <p>Thank you</p>