Routing, unlimited number of parameters

For example, the 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. The order may also be different.

The start of the route is clear:

 /shop/{category} 

And what to do next is unclear.

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

 name -> value 

Question: how to describe a route in symfony 2?

+6
source share
1 answer

Route:

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

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

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

Source: https://habr.com/ru/post/920130/


All Articles