douhuan1905 2015-12-31 07:10
浏览 14
已采纳

知道在symfony2中传递路由变量超过5的最佳方法吗?

html

<a href="{{path('href="{{path('stockitemdetails_category_report',{'itemcode':itemcode,'category':category,'subcategory':subcategory})}}">

stockregister.yml (Routing file)

 stockregister_report_itemcode_search:
                    pattern:  /stockregister/itemcode/data
                    defaults: { _controller: "EduAssetBundle:StockRegister:stockregisterItemcodeDate" }
                    requirements:
                        itemcode: .+
                        category: .+
                        subcategory: .+
                        type: .+
                        accountunit: .+



     Controller(File) 
 public function stockregisterItemcodeDateAction($itemcode,$category,$type,$accountunit) {}

here is the routing file where i define the variable which i have to pass but the problem is that the variable values is dynamic user can write anything. according to values in controller the dynamic values access and i can run query. but the problem is that the url value will be any thing.

  • 写回答

1条回答 默认 最新

  • doty58493 2015-12-31 17:33
    关注

    The regex .+ is greedy, so it will match everything it finds - including the slash. So itemcode wil match the whole of the path, as the router won't be able to work out whether a slash is part of or the end of the itemcode parameter.

    You could encode the values, so that unencoded slashes indicate the end of a parameter, whereas encoded slashes are part of the parameter value. Then you could remove the regex.

    The better solution is just to use GET, instead of making them part of the path. When you generate a URL using the router, any variables that aren't mapped in the path will be appended as GET variables anyway. If necessary, you could build a ParamConverter to automatically inject the GET variables as parameters into the action.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中