Maybe I am missing something but there doesn't seem to be a way to define querystring parameters in routes in Symfony2 so that they can be passed into a controller.
For instance, instead of generating a URI like /blog/my-blog-post
(from Symfony2's routing documentation) and passing it to the following route:
# app/config/routing.yml
blog_show:
pattern: /blog/{slug}
defaults: { _controller: AcmeBlogBundle:Blog:show }
I would prefer to generate a URI like /blog?slug=my-blog-post
. The problem is I can't find anywhere to define the slug
parameter in the route configuration file (like its {slug} counterpart above).
Perhaps this is on purpose but then what is the best practice for working with GET parameters in the querystring?
The documentation does make mention of them in Generating URLs with Query Strings, so how to pass them into the controller?
Where I can find mention of them is Symfony2 and HTTP Fundamentals:
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
// retrieve GET variables
$request->query->get('foo');
Is this the best practice for working with them inside the controller?