Reputation: 878
I am trying to write my first application with Symfony2. It's a fairly simple game just to get used to working with Symfony2, but the Routing is bugging me.
I use YAML for my routing and have the following routes:
upload:
path: /{_locale}/upload/{currentGameType}/
defaults: { _controller: BaseAcmeBundle:Default:upload, currentGameType: gameName, _locale: nl }
requirements:
_locale: nl|en
The currentGameType
is optional, and always is 'gameName', a default game if it is not set.
So when going to en/upload
the route upload:
is ignored and I get the message that the route is not found
When for example I go to the en/upload/gameName
the route does work and the gametype is set to gameName
. Why does this parameter not want to be optional?
So.. I am completely lost the pas few hours and wish for some help/pointers.
Thanks in advance.
edit: So, few minutes after posting I found out that without the trailing slashes in the routing it does work. However knowing this it is still an issue.
Upvotes: 1
Views: 382
Reputation: 2769
just create a second path:
upload_bare:
path: /{_locale}/upload/
defaults: { _controller: BaseAcmeBundle:Default:upload, _locale: nl }
requirements:
_locale: nl|en
just note that in your function you should have gameName = null by default and it should be your last argument.
Upvotes: 1