Valid types are strings, numbers, null, and objects that implement a __toString() method.
public setContent ( mixed $content ) : |
||
$content | mixed | Content that can be cast to string |
return |
use Symfony\Component\HttpFoundation\Response; $response = new Response(); $response->setContent("Hello World");
use Symfony\Component\HttpFoundation\Response; $response = new Response(); $users = [ ['name' => 'John', 'age' => 35], ['name' => 'Jane', 'age' => 27], ]; $response->setContent(json_encode($users)); $response->headers->set('Content-Type', 'application/json');In this example, we create an array of users and encode it as JSON. We set the content of the response as the JSON string and also set the content type of the response as "application/json". This method is part of Symfony HttpFoundation Component.
public setContent ( mixed $content ) : |
||
$content | mixed | Content that can be cast to string |
return |