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?
You can create a child route for your users route like this:
then you can assemble
$this->url('users/query', array('sort' => 'desc'))
.Don't forget to set
may_terminate
totrue
!This can be done using the current URL view helper yes.
You do not need to have query string child routes setup. As long as you have a route setup for 'users', you can just look for the 'sort' param in your controller and use where required.
Since version 2.1.4 you come across user error
Usage example: