What is Symfony?
Symfony is a modern, enterprise-level PHP web application framework which utilizes the latest web technologies. It enables web building in PHP and some of the finest applications to have been created on Symfony include Drupal, phpBB and eZ Publish. But it’s also much more than that. Proponents of Symfony see it, not only as a technological tool, but also as a philosophy and even as a basis for community. Symfony sets itself apart with its strong architecture, large community, developer tools, and limitless extensibility.
Why Symfony?
The Symfony framework is adaptable, scales easily, and is full-featured, reports Laeeq of Web Revisions. Symfony is used by many large companies (like the BBC or CBS), by many large websites .some Open-Source projects are also powered by Symfony (CMSes like Drupal or eZpublish, libraries like PHPUnit or Doctrine, products like phpBB or shopware, and even frameworks like PPI or Laravel). This brings a lot of interoperability between all these solutions. Symfony is not a framework but a project. Depending on your needs, you can choose to use some of the Symfony Components, the Silex micro-framework, or the full-stack framework. Symfony has plenty of reusable PHP components that can be used like Security, Templating, Translation, Validator, Form Config and more.
What are the features of Symfony?
- High-performance PHP framework
- Easy to install and configure on most platforms
- Database engine-independent
- Model-View-Controller based system
- Easily customizable to work with any data structure, API, or technology
- Simple to use, in most cases, but still flexible enough to adapt to complex cases
- Based on the premise of convention over configuration–the developer needs to configure only the unconventional
- Compliant with most web best practices and design patterns
- Enterprise-ready–adaptable to existing information technology (IT) policies and architectures, and stable enough for long-term projects
- Very readable code, with phpDocumentor comments, for easy maintenance
- Security against cross-site request forgery and other attacks
- Easy to extend, allowing for integration with other vendor libraries
What is controller in symfony?
A controller is a PHP function you create that reads information from the Request object and creates and returns a Response object. The response could be an HTML page, JSON, XML, a file download, a redirect, a 404 error or anything else you can dream up. The controller executes whatever arbitrary logic your application needs to render the content of a page.
What are bundles in symfony?
Symfony bundle are very similar to plugins or packages in other frameworks or CMS. In Symfony, everything is a bundle from core framework components to code you write. The bundle gives the flexibility to use pre-built features packaged in third-party bundles or to create and distribute your own bundles.
There are two types of bundles are available in Symfony:
Application-specific bundles: only used to build your application.
Reusable bundles: meant to be shared across many projects.
What is format of view file?
File Location: app/Resources/views/user/index.html.twig
{% extends ‘base.html.twig’ %}
{% block body %}
   <h1>
Welcome to Symfony2</h1>
{# … #}
{% endblock %}
How to get current route in Symfony?
$request = $this->container->get(‘request’);
$currentRouteName = $request->get(‘_route’);
How to create a symfony application using composer?
Run below command in your console to install Symfony using Composer:
composer create-project symfony/framework-standard-edition my_project_name
What is Symfony 2?
Symfony2 is a full-stack web framework written in PHP. Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP components that solve common web development problems. It is also  MVC framework. Symfony2 introduced truly unique HTTP and HTTP cache handling by being an HTTP-centric request/response framework, and also by allowing full use of advance features like ESI for separating the different parts of your page/application. Symfony2 is powered out of the box by a fast PHP-built Symfony reverse proxy, and for mid- to large-installations a seamless upgrade to Varnish provides a 10-20x speedup, and a far more robust cache handling.
How to create Action of controller in Symfony2?
Add following code inside UserController.php
   public function indexAction()
   {
       return $this->render(‘user/index.html.twig’, [ ]);
   }
How to set and get session in symfony2?
SessionInterface object set and get method is used to set and get sessions in Symfony2.
Below look below example:
public function sessionAction(SessionInterface $session)
{
   // store an attribute for reuse during a later user request
   $session->set(‘user_id’, 5);
  // get the attribute set by another controller in another request
   $user_id = $session->get(‘user_id’);Â
}
How to get the request parameters in symfony2?
$request->query->get(‘paraemeter_name’) method is used to get the request parameters in symfony2.
How to create controller in Symfony2?
File Location: src/AppBundle/Controller/UserController.php
Format:
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class UserController extends Controller
{
}
Why Twig use in symfony?
Twig templates are meant to be simple and won’t process PHP tags. This is by design: the Twig template system is meant to express presentation, not program logic. Twig is fast because each template is compiled to a native PHP class and cached. The more you use Twig, the more you’ll appreciate and benefit from this distinction. And of course, you’ll be loved by web designers everywhere.
What is Route?
A route is a map from a URL path to a controller. Suppose you want one route that matches /blog exactly and another more dynamic route that can match any URL like /blog/my-post or /blog/all-about-symfony:
Which template engine symfony supports?
Symfony default template engine is Twig, however, free to use plain PHP code if you want.
What are benefits of Symfony?
- MVC Pattern Robust Applications
- Speed up the creation and maintenance
- Unlimited flexibility
- Expandable
- Stable and sustainable
- Ease of use.
What are cons of Symfony?
- The security mechanism of symfony is hard to use.
- File parsing in symfony is a bit difficult task.