路由,参数数量无限

2023-11-24

例如,链接:

/shop/phones/brend/apple/display/retina/color/red

where:

phones    - category alias
brend     - name of attribute;   apple    - attribute value
display   - name of attribute;   retina   - attribute value
color     - name of attribute;   red      - attribute value

属性可以是任意数字。顺序也可能不同。

路线一开始就很明确:

/shop/{category}

下一步该做什么还不清楚。

在 symfony 1 中,末尾有一组星号(“/shop/:category/*”)以及所有未明确标记的内容,并且以一对形式出现

name -> value

问题:symfony 2 中如何描述路由?


路线:

my_shop:
  pattern: "/{path}"
  defaults: { _controller: "MyShopBundle:Default:shop" }
  requirements:
    path: "^shop/.+"

然后你可以解析控制器中的 $path :

class DefaultController extends Controller {
...
    public function shopAction($path) {
        // $path will be 'shop/phones/brend/apple/display/retina/color/red'
        ...
    }
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

路由,参数数量无限 的相关文章

随机推荐