This article mainly introduces the abandoned getRequest () method in Symfony2, analyzes the implementation principle of the getRequest method and the get and post techniques used to replace the request response, you can refer to the example in this article to analyze the abandoned getRequest () method in Symfony2. We will share this with you for your reference. The details are as follows:
When Symfony was recently used, it was found in NetBeans that the getRequest () method was abandoned:
/** * 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 found that it should be written as follows:
use Symfony\Component\HttpFoundation\Request;public function updateAction(Request $request){ $foo = $request->get('foo'); $bar = $request->get('bar');}
Use the following post method:
$foo = $request->request->get('foo');
Use the following get method:
$foo = $request->query->get('foo');