Symfomy2 get url parameter in routing condition

2019-08-13 12:18发布

问题:

I am trying to set up the following route

/**
 * @Route(
 *      "/api/list/{setName}/{order}",
 *      condition= "request.get('order') == 'something' "
 *
 * )
 */

but I can only produce 404s because the condition is never true although I pass in an order argument. I guess the "request.get('order')" part is wrong, but how to do it?

回答1:

try

       condition= "request.query.get('order') == 'something' "

instead of

       condition= "request.get('order') == 'something' "

check more help here and here



回答2:

Looking at the Routing docs with conditions, I don't find any reference to an annotation definition for route conditions. You should probably use another format.



回答3:

I suggest you to use the requirements attribute as follow:

/**
 * @Route(
 *      "/api/list/{setName}/{order}",
 *       requirements={"order":"something"}"
 *
 * )
 */

Hope this help