Skip to content

Instantly share code, notes, and snippets.

@dmouse
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save dmouse/f63f285301cec89fbe0f to your computer and use it in GitHub Desktop.

Select an option

Save dmouse/f63f285301cec89fbe0f to your computer and use it in GitHub Desktop.
Symfony Reponse examples
{
"name": "dmouse/response",
"description": "Response sample",
"require": {
"symfony/http-foundation": "2.4.*"
},
"license": "MIT",
"authors": [
{
"name": "David Flores",
"email": "[email protected]"
}
],
"minimum-stability": "dev"
}
<?php
use Symfony\Component\HttpFoundation\Response;
require __DIR__ . '/vendor/autoload.php';
$response = new Response();
$response->setContent('Hello world');
$response->setMaxAge(10);
#echo $response->send();
$response->send();
<?php
use Symfony\Component\HttpFoundation\Response;
require __DIR__ . '/vendor/autoload.php';
$response = new Response();
$response->setContent('Hello world');
$response->send();
<?php
use Symfony\Component\HttpFoundation\Response;
require __DIR__ . '/vendor/autoload.php';
$response = new Response();
echo $response->send();
<?php
use Symfony\Component\HttpFoundation\Response;
require __DIR__ . '/vendor/autoload.php';
$response = new Response();
$response->setContent(json_encode(['message'=>'Hello world']));
$response->headers->set('Content-Type', 'application/json');
$response->setMaxAge(10);
#echo $response->send();
$response->send();
<?php
use Symfony\Component\HttpFoundation\JsonResponse;
require __DIR__ . '/vendor/autoload.php';
$response = new JsonResponse();
$response->setData([
'data' => 123
]);
# echo $response->send();
$response->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment