Introduction

  • Symfony is a PHP web application.

  • It is for MVC applications.

  • Symfony is free software and released under the MIT(Massachusetts Institute of Technology) license .

  • The symfony-project.com website launched on October 18, 2005

  • Symfony aims to speed up the creation and maintenance of web applications and to replace repetitive coding tasks.

  • Symfony has a low performance overhead used with a bytecode cache.

  • Requests and Responses in Symfony


  • Symfony provides PHP approach via two classes that allow you to interact with the HTTP request and response in an easier way.

  • The Request class is a simple object-oriented representation of the HTTP request message.


  • use Symfony\Component\HttpFoundation\Request;
    
    $request = Request::createFromGlobals();
    
    // the URI being requested (e.g. /about) minus any query parameters
    
    $request->getPathInfo();
    
    // retrieve GET and POST variables respectively
    
    $request->query->get('name');
    
    $request->request->get('bar', 'default value if bar does not exist');
    
    // retrieve SERVER variables
    
    $request->server->get('HTTP_HOST');
    
    // retrieves an instance of UploadedFile identified by name
    
    $request->files->get('name');
    
    // retrieve a COOKIE value
    
    $request->cookies->get('PHPSESSID');
    
    // retrieve an HTTP request header, with normalized, lowercase keys
    
    $request->headers->get('host');
    
    $request->headers->get('content_type');
    
    $request->getMethod(); // GET, POST, PUT, DELETE, HEAD
    
    $request->getLanguages(); // an array of languages the client accepts