Multi optional parameters in route symfony

1k Views Asked by At

I have route like this:

   * @Route(
   *        "/search/{ro}/{mind}/{his}",
   *        name="search",
   *        requirements={"ro"="[a-zA-Z]{2,}", "mind"="()|new|old", "his"="()|yes|ok|no"}
   *    )

if I want this url: /search/yes I need to enter this address: /search///yes to show page.
how can remove // from original url?

1

There are 1 best solutions below

0
Rufinus On

welcome to stackoverflow,

you know you can have multiple routes for one action?

Just be aware of the order of the routes - the more parameters the higher - or a lesser route will catch first.

   * @Route(
   *        "/search/{ro}/{mind}/{his}",
   *        name="search",
   *        requirements={"ro"="[a-zA-Z]{2,}", "mind"="()|new|old", "his"="yes|ok|no"}
   *    )

   * @Route(
   *        "/search/{his}",
   *        name="search_short",
   *        requirements={"his"="yes|ok|no"}
   *    )