Hi Vaclav,

With ZF2 query params are now first class citizens with regards to routing.

If you are assembling your outgoing urls in your controller or view, using
the url helpers, you can add query parameters like this:

```
$from = 0;
$to = 100;
$myUrl = $this->url('route-name', array(/*params*/), array('query' =>
array('fPriceFrom'=> $from, 'fPriceTo' => $to)));
```

This should work to *create* the query urls.

In order to get the values of parameters, you can do this:

```
$from = $this->getRequest()->getQuery('fPriceFrom', false);
$to = $this->getRequest()->getQuery('fPriceTo', false);
if ($from && $to) {
    //we have from and to, do special query here
} else {
    //no params, do default search
}
```

Hopefully, this helps. Hit me up if you get stuck.

Cheers,

Michael Gooden


On 22 May 2013 07:53, Václav Vaník <vaclav.va...@gmail.com> wrote:

> Hi,
>
> what is the best practise for handling query string params?
>
> In ZF1 I have filter form, submit with POST, then redirect with GET and
> final URL is something like: /product/index/fPriceFrom/0/fPriceTo/100
>
> select product where price is between 0 and 100. With magic default route,
> it was easy. I write simply in view script something like
>
> <a href=&quot;&lt;?php echo $this->url(array('action' => 'add')); ?>">add
> product
>
> As I see in ZF2, default route is deprecated. I have to create routes I
> need. Ok, no problem. It makes me sense. But how to easy handle query
> string
> params? Should I write own view helper? Whats the suggested way?
>
> Thx.
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/Handling-query-string-params-within-ZF2-tp4660091.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>
>

Reply via email to