Is that possible with symfony2 to define multiple url patterns for a single Controller Action using regular expressions, so we don't have to define several rules ? Thanks in advance
When using annotations, you can define multiple routes. Like that:
/**
* @Route ("item1")
* @Route ("item/2")
* @Method("GET")
*/
public function itemAction() {
}
I'm using Version 2.0.9
Do you mean placeholders with requirements?
blog:
pattern: /blog/{page}
defaults: { _controller: AcmeBlogBundle:Blog:index, page: 1 }
requirements:
page: \d+
Here you have multiple routes defined by a placeholder, validated by regular expressions going to the same controller action.
Edit:
Each part of the url can be a placeholder.
blog:
pattern: /{type}/{page}
defaults: { _controller: AcmeBlogBundle:Blog:index, page: 1 }
requirements:
type: blog|articles
page: \d+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With