Creates a new request with values from PHP's super globals.
public static createFromGlobals ( ) : Request | ||
return | Request | A new request |
use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); echo $request->getUri(); // outputs current URI echo $request->getMethod(); // outputs request method (GET, POST, etc.)
use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); if ($request->isXmlHttpRequest()) { // handle AJAX request } else { // handle regular request }In this example, we create a request object using `createFromGlobals` method and use the `isXmlHttpRequest` method to determine if the request was sent via AJAX. Overall, the `createFromGlobals` method is a convenient way to create a new HTTP request object in Symfony PHP applications while extracting data from various superglobals.
public static createFromGlobals ( ) : Request | ||
return | Request | A new request |