路由,无限数量的参数 [英] Routing, an unlimited number of parameters

查看:105
本文介绍了路由,无限数量的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,链接:

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

其中:

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

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

Attributes can be any number. Order may also be different.

路线的起点很明确:

/shop/{category}

接下来的操作尚不清楚。

And what to do next is unclear.

在symfony 1中,一组位于末尾的星号( / shop /:category / *)和所有未明确标记的东西,并成对

In symfony 1, a set at the end star ("/shop/:category/*") and all that was not clearly marked, and come in a pair of

name -> value

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

Question: how to describe the route in symfony 2?

推荐答案

路线:

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

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

and then you could just parse the $path in the controller:

class DefaultController extends Controller {
...
    public function shopAction($path) {
        // $path will be 'shop/phones/brend/apple/display/retina/color/red'
        ...
    }
...
}

这篇关于路由,无限数量的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆