Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you add query parameters in the ZF2 / ZF3 url view helper

Tags:

I'm attempting to create a url with a query string using a route, like so:

$this->url('users') -> /users $this->url('users', ['sort' => 'desc']) -> /users?sort=desc 

However this doesn't seem to work (the second helper actually outputs /users). According to this unofficial, out-of-date documentation there was once a way to do this by appending /query to the route name, however this gives a route-not-found exception.

Can this be done using the current url helper?

like image 971
Ross Avatar asked Oct 08 '12 15:10

Ross


1 Answers

Since version 2.1.4 you come across user error

Query route deprecated as of ZF 2.1.4; use the "query" option of the HTTP router\'s assembling method instead

Usage example:

$name    = 'index/article'; $params  = ['article_id' => $articleId]; $options = [         'query' => ['param' => 'value'],      ]; $this->url($name, $params, $options); 
like image 58
dVaffection Avatar answered Sep 17 '22 17:09

dVaffection