0

I am experiencing some issues with optional parameters in my routes. I think I did it properly according to the documentation but still it is not working.

So I have the following route defined:

test_wizard:
    pattern:  /test/wizard/{testName}/{step}/
    defaults: { _controller: TestBundle:Wizard:wizard, step: 1 }

and would like the route to be able to be called by /test/wizard/someTestName and then fill in the step parameter with the default value of 1 but everytime I call the route just with the test name I get the following instead:

No route found for "GET /test/wizard/someTestName" 

When I call the route by /test/wizard/someTestName/1/ itworks just fine. Why is my defined default value for step not working? Any suggestions? Thanks.

RaHe
  • 351
  • 1
  • 4
  • 19
  • 1
    try removing the last / of your route definition – brpaz Jan 12 '14 at 18:41
  • Cool. That did the trick. Thanks. But now whenever I try the route /test/wizard/someTestName/1/ I got the "No route found for" message. Why is Symfony not able to handle /1 and /1/ as the same? – RaHe Jan 12 '14 at 18:47

1 Answers1

1

It is not possible to make a parameter optional if you have a character after it (/ in your case). You have to define two routes:

test_wizard:
    pattern:  /test/wizard/{testName}
    defaults: { _controller: TestBundle:Wizard:wizard }

test_wizard_optional:
    pattern:  /test/wizard/{testName}/{step}/
    defaults: { _controller: TestBundle:Wizard:wizard, step: 1 }
Vitalii Zurian
  • 17,858
  • 4
  • 64
  • 81