use Symfony\Component\HttpFoundation\Response; $response = new Response(); $response->setContent('Hello, World!'); $response->setStatusCode(Response::HTTP_OK); $response->headers->set('Content-Type', 'text/html'); $response->send();
use Symfony\Component\HttpFoundation\Response; $response = new Response( 'Hello, World!', Response::HTTP_OK, array('content-type' => 'text/html') ); $response->send();This example demonstrates creating a new Response object with the same parameters as the previous example, but using the constructor to set the values instead of setting them individually. Overall, the Response __construct method is a powerful tool for creating and customizing HTTP responses in PHP and is a part of the Symfony\Component\HttpFoundation package library.