Symfomy2 get url parameter in routing condition

假如想象 提交于 2019-12-11 11:07:36

问题


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



来源:https://stackoverflow.com/questions/32201464/symfomy2-get-url-parameter-in-routing-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!