在控制器中使用什么代替 getRequest()->get(...) [英] What to use instead of getRequest()->get(...) in controller

查看:37
本文介绍了在控制器中使用什么代替 getRequest()->get(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我浏览了 symfony2 api 文档,这是我在 Request 的文档中找到的内容 get 方法:

Recently I browsed symfony2 api docs and here is what i've found in documentation for Request's get method:

避免在控制器中使用此方法:

Avoid using this method in controllers:

  • 更喜欢从命名"中获取来源

那么named"是什么?我应该使用 source 而不是 get 方法?

So what is the "named" source that I should use instead of get method?

推荐答案

"named" source 将是合适的参数包:

"named" source would be appropriate parameter bag:

  • $request->query 获取 GET 参数
  • $request->attributes 用于请求属性(从 PATH_INFO 解析)
  • $request->request POST 参数
  • $request->query for GET parameters
  • $request->attributes for request attributes (parsed from PATH_INFO)
  • $request->request for POST parameters

get 方法简单地遍历所有这些,直到它通过名称找到一个参数.因此它的速度很慢.请参阅实施.

get method simply goes through all of them until it finds a parameter by name. Therefore its slow. See the implementation.

这篇关于在控制器中使用什么代替 getRequest()->get(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆