1. HTTP fundamentals

Created Thursday 29 May 2014

http://symfony.com/doc/current/book/http_fundamentals.html

use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
$request->getPathInfo(); // URI
$request->query->get('foo'); // GET var
$request->request->get('bar', 'default if bar doesn\'t exist'); // POST var
$request->server->get('HTTP_HOST'); // SERVER var
$request->files->get('foo'); // Instance of UploadedFile
$request->cookies->get('PHPSESSID'); // Cookie value
$request->headers->get('host');
$request->headers->get('content_type');
$request->getMethod(); // GET, POST, PUT, DELETE, HEAD
$request->getLanguages(); // Array of lans the client accepts

use Symfony\Component\HttpFoundation\Response;
$response = new Response();

$response->setContent('<html><body><h1>Hello world!</h1></body></html>');
$response->setStatusCode(Response::HTTP_OK);
$response->headers->set('Content-Type', 'text/html');

// prints the HTTP headers followed by the content
$response->send();




Backlinks: