Home  >  Article  >  Backend Development  >  Analysis of the abandoned getRequest() method in Symfony2, symfony2getrequest_PHP tutorial

Analysis of the abandoned getRequest() method in Symfony2, symfony2getrequest_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:56:47996browse

Analysis of the abandoned getRequest() method in Symfony2, symfony2getrequest

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.

Articles you may be interested in:

  • Detailed explanation of Symfony2 framework project creation and template setting examples
  • Symfony2 study notes plug-in format analysis
  • Symfony2 study notes Detailed explanation of system routing
  • Detailed explanation of controller usage in Symfony2 study notes
  • Detailed explanation of template usage in Symfony2 study notes
  • Example analysis of controller usage in Symfony2 development
  • Graphic tutorial on the configuration method of Symfony2 under Nginx
  • Symfony2 installation method (2 methods)
  • Symfony2 session usage example analysis
  • A classic introduction to the high-performance PHP framework Symfony2 Tutorial
  • Detailed explanation of HTTP Cache usage in Symfony2 framework study notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111338.htmlTechArticleAnalysis of the abandoned getRequest() method in Symfony2, symfony2getrequest This article analyzes the abandoned getRequest() in Symfony2 with an example method. Share it with everyone for your reference, the details are as follows:...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn