Reputation: 91
I've playing around with annotations in Symfony2.5 and am struggling to output a nice clean url like this:
.../display&type=foo&id=1
What I always get is:
.../display%26type=foo%26id=1
Why is Symfony2 url encoding this?
My controller looks like this:
/**
* Displays content
*
* @Route("/display/type={type}&id={id}", name="content_display")
* @Template(...)
*/
public function displayAction($type, $id = null) {
...
}
my twig template has:
<a href="{{ path('content_display', {'type': type, 'id': entity.id}) }}">{{ entity.id }}. {{ entity.name }}</a><br />
So I've tried to add |raw
and autoescape off tags described here. But no luck so far, any ideas?
Thanks!
Upvotes: 0
Views: 1588
Reputation: 10292
/display/type={type}&id={id}
...is not a valid URL... you'd have to replace that second slash with a ?
:
/display?type={type}&id={id}
That said, the route is meant for path replacement -- not parameter replacement.
I'm pretty certain that if you change that to simply /display
, when you try to render the URL with your key-value map, then Symfony will add those as parameters, since it can't find those keys in the path itself.
Edit:
Confirmed via the documentation:
The generate method takes an array of wildcard values to generate the URI. But if you pass extra ones, they will be added to the URI as a query string.
Upvotes: 2