symfony The Request


Symfony's Request class is an object-oriented representation of the HTTP request. It contains information such as the URL, query string, uploaded files, cookies and other headers coming from the browser.


  • $request->getPathInfo(); // returns the path (local part of the URL) that is being requested (but without the query string). I.e. when visiting, this will contain /foo/bar
  • $request->query->get('id'); // returns a query string parameter ($_GET)
  • $request->query->get('id', 1); // returns a query string parameter with a default value
  • $request->request->get('name'); // returns a request body variable ($_POST)
  • $request->files->get('attachment'); // returns an instance of UploadedFile identified by "attachment"
  • $request->cookies->get('PHPSESSID'); // returns the value of a cookie ($_COOKIE)
  • $request->headers->get('content_type'); // returns an HTTP request header
  • $request->getMethod(); // returns the HTTP request method (GET, POST, PUT, DELETE, etc.)
  • $request->getLanguages(); // returns an array of languages the client accepts