Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the getRequest () method in Symfony2

Shulou Source: shulou.com Published: 2022-06-03 13:03:45 11月16日 Update

Editor to share with you how to use the getRequest () method in Symfony2, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The details are as follows:

When using Symfony recently, it was 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 ();}

Google took a moment and 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');}

For post, please use:

$foo = $request- > request- > get ('foo')

For get, please use:

$foo = $request- > query- > get ('foo'); this is all the content of the article "how to use the getRequest () method in Symfony2". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Methods articles content methods not much most more knowledge industry information information channels channels references learning help abandonment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft MySQL NVidia Apple