Sets the request format.
public setRequestFormat ( string $format ) | ||
$format | string | The request format |
use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); $request->setRequestFormat('json');
use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); if ($request->headers->has('Accept')) { $acceptHeader = $request->headers->get('Accept'); switch ($acceptHeader) { case 'application/json': $request->setRequestFormat('json'); break; case 'application/xml': $request->setRequestFormat('xml'); break; default: $request->setRequestFormat('html'); break; } }In this example, we are checking the Accept header of the request and setting the request format accordingly. If the Accept header is 'application/json', the request format is set to JSON, if it is 'application/xml', the request format is set to XML, and if it is anything else, the request format is set to HTML. Package library: Symfony\Component\HttpFoundation
public setRequestFormat ( string $format ) | ||
$format | string | The request format |