Symfony2中被遗弃的getRequest()方法分析
本文实例分析了Symfony2中被遗弃的getRequest()方法。分享给大家供大家参考,具体如下:
最近使用Symfony时,在NetBeans中发现getRequest()方法被遗弃了:
/**
*Shortcuttoreturntherequestservice.
*
*@returnRequest
*
*@deprecatedDeprecatedsinceversion2.4,toberemovedin3.0.Ask
*SymfonytoinjecttheRequestobjectintoyourcontroller
*methodinsteadbytypehintingitinthemethod'ssignature.
*/
publicfunctiongetRequest()
{
return$this->container->get('request_stack')->getCurrentRequest();
}
Google了一下,发现应该这么写:
useSymfony\Component\HttpFoundation\Request;
publicfunctionupdateAction(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程序设计有所帮助。
热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短