Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing, an unlimited number of parameters

For example, link:

/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

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

The beginning of the route is clear:

/shop/{category}

And what to do next is unclear.

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

Question: how to describe the route in symfony 2?

like image 707
ddmaster Avatar asked Jul 10 '12 14:07

ddmaster


1 Answers

The route:

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

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'
        ...
    }
...
}
like image 68
Tom Imrei Avatar answered Sep 28 '22 00:09

Tom Imrei