[英]Optional prefix for route in Symfony2
I want to these URLs all match same controller: 我希望这些URL都与同一控制器匹配:
/
/7
/articles
/articles/
/articles/7
Is it possible to add optional prefix
to symfony's routing so the article
prefix be optional? 是否有可能可选的添加
prefix
到symfony中的路由使article
前缀是可选?
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.对于该框架,有很长时间的补丁程序来实现
/(articles/){id}
类的路由,该路由将与您在上面设置的功能相匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.