【发布时间】:2016-03-11 15:50:30
【问题描述】:
我有以下路由配置:
# Resources/config/routing.yml
AcmeBundle_article:
resource: "@AcmeBundle/Resources/config/routing/article.yml"
prefix: /article
# Resources/config/routing/article.yml
acme_article:
path: /{page}
defaults: { _controller: AcmeBundle:Article:index, page: 1 }
每当我调用$this->redirect($this->generateUrl('acme_article')) 或{{ path('acme_article') }} 时,URL 都会不带斜杠/,例如example.com/article。我希望它像
example.com/article/ example.com/article/1example.com/article/2
当我改变路由时没有{page}参数如下
# Resources/config/routing/article.yml
acme_article:
path: /
defaults: { _controller: AcmeBundle:Article:index }
然后,按照我的预期添加尾部斜杠:
example.com/article/example.com/article/?page=1example.com/article/?page=2
但是,我想在路由中保留{page},并且只想在没有页面参数时添加斜杠。是否可以在 Symfony 2 路由中做?
【问题讨论】: