$data = ['name' => 'John', 'age' => 25]; $response = new Response(); $response->setData(json_encode($data)); $response->send();
$data = 'In this example, we set a HTML string as the response data and send it to the client. The client's browser will render it as a web page. Package Library: The Response setData method is part of the Symfony HttpFoundation component. This component provides a set of classes for creating and managing HTTP requests and responses in PHP.My Page Welcome to my page
'; $response = new Response(); $response->setData($data); $response->send();