Symfony interview questions

Symfony interview questions | Freshers & Experienced

  • Janhavi Jaiswal
  • 12th Apr, 2021
  • 510 Followers

Key Features of Symfony

Below are few major features of Symfony

User-Friendly URLs

Opensource

Stable and Sustainable

Easy Testing

Better security

Faster development

Long-term support

Big community

Good documentation

Q1. What is symfony? List some features?

Symfony is a complete web framework and set of reusable components that are easily used in other applications and frameworks. It is written by Fabien Potencier and first released on 22 October 2005.

Major Key Features of Symfony Framework are

  • Easy to install
  • Highly scalable
  • Open Source
  • Large and active Community.
  • Flexible routing.
  • Based on the MVC design pattern.
  • Clean and elegant template engine.
  • Easy testing and long-term support.
  • Good documentation

Q2. What are symfony bundles?

Symfony bundles are a directory or folder where we put all related files of a module. Generally, a Bundle contains the following directories and files.

  • Controller Directory: Contains controllers of the bundle
  • DependencyInjection Directory: Hold Dependency Injection Extension classes
  • Resources/config/ Directory: Contains configuration files like routing.yaml
  • Resources/views/ Directory: Contain view files of the bundle.
  • Resources/public/ Directory: Contains static resources such as images, stylesheets of a bundle.
  • Tests/ Directory: Contains all test files for the bundle.

Q3. What are components in symfony?

Symfony Components are a set of decoupled and reusable PHP libraries. It is open-source software that aims to speed up the creation and maintenance of web applications and to replace repetitive coding tasks and also building robust applications in an enterprise context and aims to give developers full control over the configuration.

Q4. Does laravel use symfony?

Yes, Laravel uses Symfony components internally. Around 30% of Laravel framework is built on Symfony.

Q5. Symfony logs are stored in which directory?

Symfony stores all logs in log directory of your project.

Q6. How to clear cache in Symfony?

To clear cache in Symfony you can use cache:pool:clear command. This command will delete all data from the project storage directory. By default, Symfony comes with 3 cache clearers. They are

  • cache.global_clearer
  • cache.system_clearer
  • cache.app_clearer

Q7. How to create a bundle in Symfony?

The Symfony bundle is a group of files and directories that are organized into a specific structure.

To create a bundle in Symfony follow below steps:

Step1: Choose a namespace. The namespace must contain the name of the vendor and bundle name. Something like Courseya\DemoBundle.

Step2: Create an empty class named CourseyaDemoBundle and extend it to Bundle class.

Example:

namespace Courseya\DemoBundle; 
use Symfony\Component\HttpKernel\Bundle\Bundle;  

class CourseyaDemoBundle extends Bundle { 
}

Step3: Save the above class in src/Courseya/DemoBundle directory.

Step4: Register the above class in the bundle list supported by the application in the AppKernel class. Example:

public function registerBundles() { 
   $bundles = array( 
      // ... 
      // register your bundle 
      new Courseya\DemoBundle\CourseyaDemoBundle(), 
   ); 
   return $bundles; 
}

Step5: Use generate:bundle command to generate your bundle.

php bin/console generate:bundle --namespace = Courseya/DemoBundle

That's all you have created your first bundle in Symfony.

Q8. What are annotations in Symfony?

Annotations in Symfony are used for configuration of validation and mapping Doctrine information. Annotations are easy and convenient to use. In Standard Edition of Symfony, we have two additional bundles SensioFrameworkExtraBundle and JMSSecurityExtraBundle which provide better support for annotations. Using these bundles you can use annotations for controller configuration, routing, cache, security, template, etc

Q9. How to create and remove session in Symfony Framework?

In Symfony Session class is used to work with sessions. This class can perform all functions of native PHP sessions.

Below is an example of creating and removing session in Symfony.

Creating Session in Symfony

  $session = new Session();
  $session->start();

Setting Session in Symfony

  $session->set('user_id', 200);

Getting session in Symfony

 $session->get('user_id');

Removing / Destroying session in Symfony

  $session->remove('user_id');

Q10. Which template engine Symfony uses?

Symfony uses twig template engine. Twig is a flexible, fast, and secure and opensource template engine for PHP and originates its syntax from Jinja and Django templates. It is licensed under a BSD License and maintained by Fabien Potencier.

Q11. What is minimum requirement to install Symfony?

Directives are configuration options in Nginx. Each option has a name and parameters and must end with a semicolon (;).Directives are used to control Modules and divided into simple directives and block directives.

Below is the list of few Nginx Directives:

  • absolute_redirect
  • add_before_body
  • auth_basic
  • auth_jwt
  • auth_http_timeout
  • debug_connection
  • fastcgi_cache_key

View: Complete Nginx Directives Lists

Q12. How to check installed version of Symfony?

If you have access to the command line then you can use php bin/console about the command to view the installed version of the Symfony framework.

You can get the version of Symfony in symfony/src/Symfony/Component/HttpKernel/Kernel.php file.

Q13. What are bundles in Symfony?

The Symfony bundle is a collection of organized files and folders that are modeled in a specified structure. Bundles can be reused in multiple applications. Everything in Symfony is a bundle.

Q14. What are Descriptors in Symfony?

Descriptors are objects in Symfony that are used to render documentation and information on Console.

Q15. What is a controller in Symfony?

The controller in Symfony is a class that accepts requests and return a Response object.DefaultController class in Symfony is located in the src/AppBundle/Controller directory.

Q16. Enlist few form helper functions of Symfony?

Below we have listed some form helper functions of Symfony Framework

  • createFormBuilder()
  • createForm()
  • form_tag()
  • submit_image_tag()
  • input_date_tag()
  • select_language_tag()
  • options_for_select()
  • object_input_tag()

Q17. How to set and get Session in Symfony2?

Below is sample code to set and get Session in Symfony2

use Symfony\Component\HttpFoundation\Session\Session;

$session = new Session();
$session->start();

// set and get session attributes
$session->set('name', 'Drak');
$session->get('name');

About Author :

  • Author of Symfony interview questions

    Janhavi Jaiswal

    Janhavi is a Digital marketing expert and technical content writer. She like solving problems and delivering results that make positive impacts.She is quick learner.

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.