Is there a recommended way of choosing how to give data to a controller?
Often I have to decide if I want to use route place holders like:
/**
* @Route("/hello/{name}", name="hello")
*/
public function indexAction($name)
{
return new Response('<html><body>Hello '.$name.'!</body></html>');
}
Usage: /hallo/Thorsten
Or use query parameters ($_GET):
/**
* @Route("/hello")
*/
public function indexAction()
{
$request = Request::createFromGlobals();
$name = $request->get('name');
return new Response('<html><body>Hello '.$name.'!</body></html>');
}
Usage: /hallo?name=Thorsten
I don't think there is a rule for this, it depends.
Is the value a generic string possibly containing spaces or weird characters or symbols or maybe slashes? I'd use the query string, it's widely used for searches, pagination and such.
Is the value in a set of predefined "words" or "numbers", like categories, user IDs, blog post slugs and such? I'd use the path for simplicity and to follow SEO rules.
Take a look here for more information on what I mean: http://googlewebmastercentral.blogspot.co.nz/2015/04/better-presentation-of-urls-in-search.html