时时商务社区

标题: Symfony2中被遗弃的getRequest()方法分析 [打印本页]

作者: xgnic    时间: 2018-2-14 05:38

            本文实例分析了Symfony2中被遗弃的getRequest()方法。分享给大家供大家参考,具体如下:
最近使用Symfony时,在NetBeans中发现getRequest()方法被遗弃了:
/**
* Shortcut to return the request service.
*
* @return Request
*
* @deprecated Deprecated since version 2.4, to be removed in 3.0. Ask
*       Symfony to inject the Request object into your controller
*       method instead by type hinting it in the method's signature.
*/
public function getRequest()
{
  return $this->container->get('request_stack')->getCurrentRequest();
}
Google了一下,发现应该这么写:
use Symfony\Component\HttpFoundation\Request;
public function updateAction(Request $request)
{
  $foo = $request->get('foo');
  $bar = $request->get('bar');
}
post方式请使用:
$foo = $request->request->get('foo');
get方式请使用:
$foo = $request->query->get('foo');
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总
希望本文所述对大家PHP程序设计有所帮助。
            
            
您可能感兴趣的文章:
  • 高性能PHP框架Symfony2经典入门教程
  • Symfony2 session用法实例分析
  • Symfony2安装的方法(2种方法)
  • Symfony2在Nginx下的配置方法图文教程
  • Symfony2开发之控制器用法实例分析
  • Symfony2学习笔记之模板用法详解
  • Symfony2学习笔记之控制器用法详解
  • Symfony2学习笔记之系统路由详解
  • Symfony2学习笔记之插件格式分析
  • Symfony2框架创建项目与模板设置实例详解
  • Symfony2框架学习笔记之HTTP Cache用法详解
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2