Symfony Interview Questions: Symfony Interview Questions and Answers. Symfony is a set of reusable PHP components and a PHP framework to build web applications, APIs etc
Symfony Interview Questions
Q:- What is Symfony?
  1. Symfony is a web application framework.
  2. Symfony support MVC design pattern.
  3. Symfony is a set of reusable PHP components to build web applications, APIs, microservices and web services.
Q:- In which language Symfony is written?

In PHP Language.

Q:- What are the benefits of using Symfony?
  1. Fast Development:

    Reusing generic components/Libraries- Symfony provides many such components and libraries which can be reused.

  2. MVC Pattern:

    Symfony supports MVC design pattern.

  3. Unlimited flexibility
  4. Expandable
  5. Stable and sustainable
  6. Ease of use.
Q:- How to install Symfony Application using Composer?
Installing & Setting up the Symfony Framework

>> To create your new Symfony application, first make sure you're using PHP 7.1 or higher and have Composer installed

>> Run the following command in cmd to install Symfony using Composer

composer create-project symfony/website-skeleton myFirstProject

The website-skeleton is optimized for traditional web applications. If you are building microservices, console applications or APIs, consider using the much simpler skeleton project:

composer create-project symfony/skeleton myFirstProject cd myFirstProject composer require symfony/web-server-bundle --dev
Running your Symfony Application

>> Move into your new project and start the server:

cd myFirstProject php bin/console server:run

Open your browser and navigate to http://localhost:8000 If everything is working, you'll see a welcome page.

You may also like - Top 50 Laravel Interview Questions
Q:- How to get the request parameters in Symfony2?

Syntax: $request->query->get("paraemeter_name");

use Symfony\Component\HttpFoundation\Request; public function updateAction(Request $request) { // $_GET parameters $request->query->get('name'); // $_POST parameters $request->request->get('name'); } //You can also get all the form values as array by using the following: $request->request->all();
Q:- Which Template Engine does Symfony Support?

Twig is a modern fast, flexible, and secure template engine for PHP.

Q:- How to get the current route in Symfony?

You can get current route in Symfony using following code:

$request->get("_route"); //OR with Twig {{ app.request.attributes.get('_route') }}
You may also like - RESTful Web Services Interview Questions
Q:- What is Serializer in Symfony?

Symfony provides a serializer to serialize/deserialize to and from objects and different formats (e.g. JSON or XML).

composer require symfony/serializer-pack
Read more about Serializer
What are the form helper functions in Symfony?

The form helpers provide a faster way to write form inputs in templates, especially for complex elements such as dates, drop-down lists, and rich text.

In Symfony, following form helper functions are given below:

  • form_tag()
  • input_tag()
  • input_password_tag()
  • input_hidden_tag()
  • textarea_tag()
  • input_file_tag()
  • select_tag()
  • options_for_select()
  • checkbox_tag()
  • submit_tag()
// Text field (input) echo input_tag('name', 'default value'); // Long text field (text area) echo textarea_tag('name', 'default content', 'size=10x20'); // Check box echo checkbox_tag('single', 1, true); // To specify option names, use an associative array echo select_tag('name', options_for_select(array( 'male' => 'Male', 'female' => 'Female', 'others' => 'Others' ), 'Male')); // Upload file field echo input_file_tag('name'); // Password field echo input_password_tag('name', 'value'); // Hidden field echo input_hidden_tag('name', 'value'); // Submit button (as text) echo submit_tag('Save');