I want to these URLs all match same controller:
/
/7
/articles
/articles/
/articles/7
Is it possible to add optional prefix
to symfony's routing so the article
prefix be optional?
How?
You can create 2 routeds pointing to the same controller:
acme_article_prefix:
path: /articles/{id}
requirements:
id: \d+
defaults: { id: 5 }
acme_article:
path: /{id}
requirements:
id: \d+
defaults: { id: 5 }
Another option is to make the prefix a placeholder too:
acme_article:
path: /{_prefix}/{id}
defaults: { _prefix: articles, id: 5 }
requirements:
id: \d+
_prefix: articles
for the framework, there is a patch for a long time to implement routes like
/(articles/){id}
, which will match the urks you set above.