Gets the current response content.
public getContent ( ) : string | ||
return | string | Content |
use Symfony\Component\HttpFoundation\Response; use GuzzleHttp\Client; $client = new Client(); $response = $client->get('https://example.com/api/data'); $responseContent = $response->getContent();
use Symfony\Component\HttpFoundation\Response; class MyController { public function index() { $htmlContent = 'In this example, we have a controller that generates HTML content and returns it as a response. We can retrieve the content of the response using the getContent method and store it in the $responseContent variable. Overall, the Response getContent method is a simple but useful method in the Symfony\Component\HttpFoundation package library that can be used to retrieve the content of a response.My Page Hello, world!
'; return new Response($htmlContent); } } $response = $controller->index(); $responseContent = $response->getContent();