Symfony2中被遺棄的getRequest()方法分析
本文實例分析了Symfony2中被遺棄的getRequest()方法。分享給大家供大家參考,具體如下:
最近使用Symfony時,在NetBeans中發(fā)現(xiàn)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了一下,發(fā)現(xiàn)應(yīng)該這么寫:
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');
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《php日期與時間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
- Symfony2框架創(chuàng)建項目與模板設(shè)置實例詳解
- Symfony2學(xué)習(xí)筆記之插件格式分析
- Symfony2學(xué)習(xí)筆記之系統(tǒng)路由詳解
- Symfony2學(xué)習(xí)筆記之控制器用法詳解
- Symfony2學(xué)習(xí)筆記之模板用法詳解
- Symfony2開發(fā)之控制器用法實例分析
- Symfony2在Nginx下的配置方法圖文教程
- Symfony2安裝的方法(2種方法)
- Symfony2 session用法實例分析
- 高性能PHP框架Symfony2經(jīng)典入門教程
- Symfony2框架學(xué)習(xí)筆記之HTTP Cache用法詳解
相關(guān)文章
php中創(chuàng)建和調(diào)用webservice接口示例
這篇文章主要介紹了php中創(chuàng)建和調(diào)用webservice接口示例,包括webservice基本知識、webservice服務(wù)端例子、webservice客戶端例子,需要的朋友可以參考下2014-07-07php筆記之:php函數(shù)range() round()和list()的使用說明
本篇文章介紹了,php函數(shù)range() round()和list()的使用說明。需要的朋友參考下2013-04-04Laravel構(gòu)建即時應(yīng)用的一種實現(xiàn)方法詳解
這篇文章主要給大家介紹了關(guān)于Laravel構(gòu)建即時應(yīng)用的一種實現(xiàn)方法,即時通訊在我們?nèi)粘5拈_發(fā)中經(jīng)常會遇到,本文通過示例代碼介紹的非常詳細(xì),需要的朋友們可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-08-08