Reputation: 345
I have route: /user/username/{username}.{_format}
And username
could have any symbols.
For example, all of the follows will be valid:
user
user.name
[email protected]
[email protected]
user.name jr
user'o name
and so on...
each part of username
could have any characters...
Also _format
is optional string e.g json
, xml
...
How I can describe it in my routing rules?
At now I have this:
MyBundle_getUserByUsername:
pattern: /user/username/{username}
defaults: { _controller: MyBundle:User:getUserByUsername, _format: json }
requirements:
_method: GET
username: ".+"
But it not so useful as it could be. I can't specify format
parameter...
I need your help guys...
Upvotes: 2
Views: 911
Reputation: 2733
MyBundle_getUserByUsername:
pattern: /user/username/{username}.{_format}
defaults: { _controller: MyBundle:User:getUserByUsername, _format:json}
requirements:
_method: GET
username: ".+(?<=.)"
Upvotes: 1
Reputation: 10126
Use the lazy quantificator
MyBundle_getUserByUsername:
pattern: /user/username/{username}.{_format}
defaults: { _controller: MyBundle:User:getUserByUsername, _format: json }
requirements:
username: ".+?"
_method: GET
_format: html|json
Upvotes: 0