Medium Level Symfony Interview Questions
11. Explain Bundles in Symfony?
Ans. Symfony bundles are the same as packages or plugins in other frameworks or CMS ( Content Management Systems). It is a group of directories organized in a specific structure. Pre-built features packaged in third-party bundles are flexible and can be utilized to create or distribute our own bundles.
12. Discuss innovations in Symfony2?
Ans. Following are the innovations provided by Symfony2:
- Dependency Injection Pattern
- Easy debugging
- Everything is bundled
- High Security
13. What are Annotations in Symfony?
Ans. Annotations in the Symfony framework configure validation and map the doctrine details. It can be used for templates, cache, routing, securing, etc. Two additional bundles can also be used for this. They are SensioFrameworkExtraBundle and JMSSecurityExtraBundle.
14. Describe Environment in Symfony.
Ans. An Environment is a group of configurations used to run applications. By default, it has two environments:
- dev: It is well suited for developing applications locally
- prod: It is used for the applications on production
15. Describe the method used to handle an Ajax request on the server side.
Ans. To handle an Ajax request in the server, we use the current request object’s isXmlHttpRequest() method; if it can handle an Ajax request, it will return true, or else it will return false.
Following is the snippet to illustrate the same:
if ($request->isXmlHttpRequest()) {
// Ajax request
} else {
// Normal request
}

You can also try this code with Online PHP Compiler
Run Code
16. How to check the installed version of Symfony?
Ans. If you have access to the command line, then the installed version can be found in the PHP bin/console of the command.
If you wish to install this version of Symfony, you can do it in this file: symfony/src/Symfony/Component/HttpKernel/Kernel.php
Check this out: jQuery interview questions
17. How can you clear the cache in Symfony?
Ans. We can use the cache:pool: clear command to clear the cache in Symfony. This will delete all the data stored in the project storage directory. We have three default cache clearers in Symfony:
- system_clearer
- app_clearer
- global_clearer
18. What tasks does the Symfony controller perform?
Ans. A Symfony controller can virtually perform anything within this framework. From redirects and transfers to accessing core services to rendering templates, Symfony's controllers can be used for a variety of basic tasks.
19. In Symfony2, write the method used to get the Request Parameters.
Ans. Symfony provides a Request class which is used to request information. It is an object-oriented representation of the HTTP request message. Use the following method:
$request->query->get(‘parameter_name’)

You can also try this code with Online PHP Compiler
Run Code
20. What are the Symfony framework applications?
Ans. Following are some Symfony framework applications:
- Daily Motion
- Drupal 8
- Thelia
Must Read Web Developer Interview Questions
Hard Level Symfony Interview Questions
21. What do you mean by form Helper? List the form helper functions in Symfony.
Ans. To write form inputs in templates, we use form helpers. They are used mostly for complex elements like drop-down lists, dates, and rich text. Some of the helper functions are:
- form_tag()
- textarea_tag()
- select_tag()
- options_for_select()
- checkbox_tag()
- input_tag()
- input_file_tag()
- input_password_tag()
- input_hidden_tag()
- submit_tag()
22. What is the syntax for EmailType in Symfony?
Ans. The EmailType field in Symfony is a text field. The HTML5 input type="email"/> tag is used to render it.
Following is the syntax for EmailType in Symfony:
use Symfony\Component\Form\Extension\Core\Type\EmailType;
$builder->add('token',
EmailType::class, array(
'data' => 'hello,')
);

You can also try this code with Online PHP Compiler
Run Code
You can use the type as an array if you want to provide extra attributes to an HTML field. The data field overrides the initial value for all the fields.
23. Name the cache adapters available in Symfony.
Ans. The available cache adapters in Symfony are
- FileSystem Cache Adapter
- PHP files Cache Adapter
- APCu Cache Adapter
- Array Cache adapter
- Redis Cache Adapter
24. Does Symfony support web servers? If yes, name them.
Ans. Yes, many web servers are supported by Symfony. They are listed below:
- WAMP (Windows)
- XAMP (Multi-platform)
- LAMP (Linux)
- MAMP (Macintosh)
- Nginx (Multi-platform)
- Microsoft IIS (Windows)
- PHP built-in development web server (Multi-platform)
25. List the rules you need to follow while creating methods inside the controller.
Ans. The rules that should be followed in Symfony for creating a method within the controller:
- The “Action” suffix must be used in Action methods.
- Long controller methods should not be used; refactoring it
- The public method should be used in only actions method
- Valid response objects should be used by the action method
26. List some benefits of Symfony.
Ans: Some of the benefits of Symfony include:
- Development is fast
- Works on MVC design patterns
- It is expandable
- Better user control
- User flexibility is unlimited
- It is a feasible and stable framework
27. How to create a controller in Symfony2? Explain with an example.
Ans. A controller in Symfony is used to take information from the HTTP request and returns an HTTP response in the form of a Response object.
In Symfony, a controller can be created by extending AbstractActionController class. An example is shown below:
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController {
public function indexAction() {
return new ViewModel();
}
}

You can also try this code with Online PHP Compiler
Run Code
28. Which method is used to set and get the session in Symfony2?
Ans. To store user information between requests, Symfony offers a session object and a number of utilities. We can use the method - “SessionInterface” to set and get sessions. $session->set() is used to set an attribute, and $session->get() is used to get an attribute that some controller already sets.
Refer to the following example:
public function sessionAction(SessionInterface $session)
{
// to set an attribute
$session->set('user_id,' 10);
// to get the attribute that a controller already sets
$user_id = $session->get('user_id');
}

You can also try this code with Online PHP Compiler
Run Code
29. What is the syntax to install Symfony 2.0?
Ans. Use the following syntax to install Symfony2:
For Windows:
php -r "readfile('https://symfony.com/installer');" > symfony

You can also try this code with Online PHP Compiler
Run Code
For Mac and Linux:
sudo mkdir -p /usr/local/bin
sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
sudo chmod a+x /usr/local/bin/symfony
30. What is the method to create action in the Symfony2 controller?
Ans. In order to serve HTML, you will need to render a template, which can be done using the render() method. It is used to put the content to be rendered in a Response object.
To create an action in the Symfony2 controller, we need to implement the following method:
public function indexAction()
{
return $this->render('user/index.html.twig', [ ]);
}

You can also try this code with Online PHP Compiler
Run Code
Conclusion
In this blog, we have gone through some most important Symfony interview questions and discussed the answers in detail. These 30 questions will help you a lot in your interview rounds.
Refer to our other interview questions-related blogs like Java collection interview questions, Production Support Interview Questions, Angular 2 Interview Questions, C# interview questions for 5 years Experience, interview questions, and Selenium Interview Questions.
Refer to our guided paths on Coding Ninjas Code360 to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses and refer to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations. Do upvote our blog to help other ninjas grow.
Happy Coding!