1

I am working on a project with Symfony 3.3.10.

I defined a route with 3 parameters like this

/**
 * @Route("/{_locale}/{cat_1}/{cat_2}/{cat_3}", name="cat_site",
 *     defaults={"cat_1" = "", "cat_2" = "", "cat_3" = ""})
 */
public function catSiteAction(Request $request, $cat_1, $cat_2, $cat_3)
{ ... }

Calling the URL

[root_path]/en/x/y/z

resulted (as expected) in the method-parameters to be set to

cat_1 = 'x'
cat_2 = 'y'
cat_3 = 'z'

which ist exactly what I want.

Now I configured FOSUserBundle and for the bundles routes to work I added a requirement to the route definition to not trigger the route if cat_1 is set to 'login' or 'logout':

/**
 * @Route("/{_locale}/{cat_1}/{cat_2}/{cat_3}", name="standard_site",
 *     defaults={"cat_1" = "", "cat_2" = "", "cat_3" = ""},
 *     requirements={"cat_1": "^(?!login|logout).+"})
 */
public function catSiteAction(Request $request, $cat_1, $cat_2, $cat_3)
{ ... }

When calling the same url as before

[root_path]/en/x/y/z

this leads to a parameter setting like this:

cat_1 = 'x/y/z'
cat_2 = ''
cat_3 = ''

Obviously this is not what I intend the parameters to be and I have no clue at all why this is happening. I can't see anything in the requirements definitions or in the used regex which can cause this.

Any ideas are highly appreciated.

user3440145
  • 793
  • 10
  • 34

1 Answers1

1

The issue is you are modifying the default regular expression: [^/]+ for the cat_1 parameter:

Symfony doc

Try the following route not allowing the / to be present (edited):

requirements={"cat_1": "^(?!login|logout)[^\/]+"})
user3440145
  • 793
  • 10
  • 34
Jannes Botis
  • 11,154
  • 3
  • 21
  • 39
  • Thank you. You are right about the modifying. Unfortunately the suggested regex doesn't work. I wasn't able to fix it yet. A minor issue is that the "/" wasn't escaped but also when escaping it with "\/" the expression does not work as due to the OR-part it lets all words pass which do not include a "/"... – user3440145 Nov 24 '17 at 12:00
  • Yes, you are right. Feel free to edit the answer with the correct one once you find it. – Jannes Botis Nov 24 '17 at 12:47