没有找到带斜线的Symfony 2/3路线

时间:2017-01-04 16:46:49

标签: symfony

我有以下路线:

product_category:
  path: /{grandFatherSlug}/{fatherSlug}/{childSlug}
  defaults: { _controller: ProductCategory:productCategoryPage, fatherSlug: "",  childSlug: ""}
  options:

由于SEO建议,我希望这种路由以尾随斜杠结尾。 但我不能让它奏效。我尝试过:

product_category:
  path: /{grandFatherSlug}/{fatherSlug}/{childSlug}/
  defaults: { _controller: ProductCategory:productCategoryPage, fatherSlug: "",  childSlug: ""}
  options:

但是我找到了一条路线未找到的例外并且:

product_category:
  path: /{grandFatherSlug}/{fatherSlug}/{childSlug}/
  defaults: { _controller: ProductCategory:productCategoryPage, fatherSlug: "",  childSlug: ""}
  requirements:
    childSlug: .+
    fatherSlug: .+
    grandFatherSlug: .+

但是我得到了附加尾部斜杠的最后一个参数,是什么让我在Controller中调用str_replace来删除它。

是否有任何简单的解决方案可以实现此行为?

由于

1 个答案:

答案 0 :(得分:0)

您是否试图在正则表达式中避免使用/

product_category:
  path: /{grandFatherSlug}/{fatherSlug}/{childSlug}/
  defaults: { _controller: ProductCategory:productCategoryPage, fatherSlug: "",  childSlug: ""}
  requirements:
    childSlug: [.+^\/]
    fatherSlug: .+
    grandFatherSlug: .+