Reputation: 1922
is there a more elegant way to define optional parameters in annotated routes then to define 2 annotations?
Here's how I did it:
/**
*
* @Route("/view/{lang}/{file}", name="legacy_translation_view_file")
* @Route("/view/{lang}", name="legacy_translation_view")
* @Template()
*/
public function viewAction($lang,$file=null)
{
...
}
i've seen that the annotation class has a field named "defaults" but am not quiet sure about the syntax
thx
Upvotes: 29
Views: 32535
Reputation: 17282
Symfony has a page on @Route:
E.g maybe you can try.
/**
* @Route("/{id}/{lang}/{file}", requirements={"id" = "\d+"}, defaults={"file" = null})
*/
public function showAction($id, $lang, $file)
{
}
If null doesn't work try an empty string.
Upvotes: 49