Home > Article > Backend Development > Analysis of the abandoned getRequest() method in Symfony2, symfony2getrequest_PHP tutorial
This article analyzes the abandoned getRequest() method in Symfony2 with examples. Share it with everyone for your reference, the details are as follows:
When using Symfony recently, I found that the getRequest() method was abandoned in NetBeans:
/** * 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(); }
Googled it and found that it should be written like this:
use Symfony\Component\HttpFoundation\Request; public function updateAction(Request $request) { $foo = $request->get('foo'); $bar = $request->get('bar'); }
Please use post method:
$foo = $request->request->get('foo');
Please use the get method:
$foo = $request->query->get('foo');
Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "php-oriented "Introduction Tutorial on Object Programming", "Summary of PHP String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone in PHP programming.