Symfony Introduction

In this article, we’ll see Symfony Introduction

Symfony is a robust PHP framework that has gained immense popularity among developers for its flexibility, scalability, and extensive feature set. It follows the Model-View-Controller (MVC) architectural pattern and offers a wide range of tools and components that simplify the development of complex web applications.

If you’re new to Symfony or considering using it for your next project, this blog post will serve as a comprehensive introduction to help you understand the framework’s key concepts and advantages.

What is Symfony?

It is a set of PHP Components, a Web Application framework, a Philosophy, and a Community — all working together in harmony.

It is free software and released under the MIT license.

The first version of Symfony was released in October 2005 by project founder Fabien Potencier, coauthor of this book. Fabien is the CEO of Sensio (http://www.sensio.com/), a French web agency well known for its innovative views on web development.

Benefits

1. Reputation

Quickly accepted by professionals, Symfony is now a stable environment that is both well-known and recognized internationally. The number of its references testifies to this, as they have increased significantly since its launch. ​​It also has an active community – developers, integrators, users, and other stakeholders involved in the enrichment of this tool.

2. Immutability

It is a product of the work of the SensioLabs company. Founded more than 12 years ago, the company is a web agency that has a lot of references. Symfony Framework is today still a key tool used by its own teams to develop projects for clients. Consistency is also something, which is associated with long-term support. Today, this support is provided by SensioLabs.

3. References

Intranet, basic public sites, social networks, community sites, management of workflow and applications, etc., examples are not missing: a lot of websites and applications of all sizes and types rely on It.

This is notably the case with Yahoo!, Dailymotion, Exercise.com, Opensky.com, and also applications such as PHPBB or Drupal.

4. Innovation

It is all that can be expected from a framework: high speed, flexibility, components that can be reused, etc. Then we have a structure that was developed using best practices.

But that’s not all. Since SensioLabs has developed a habit of shaking the established order, and always striving for perfection, It (and its entire community) has developed a sense of curiosity that goes far beyond the PHP. It does not hesitate to innovate from the search of ideas elsewhere and then adapt them to the world of PHP.

5. Resources

When using It, you can be sure that you are never “alone with your screen display.” Whether with a request to public support (mailing lists, IRC, etc.) or support from the company (consulting, training, etc.), you will always find the answers to your questions.

Based on the principle that “an undocumented line is a line that does not exist”, you will also find many works dedicated to It, which will help you in developing your sites and applications.

6. Interoperability

It respects the existing standards of PHP: PHPUnit, naming conventions for classes, etc. Moreover, it also allows you to use some pieces of its software for the building blocks without necessarily using the framework as a whole.

It is so interoperable that in its core it uses external software for building blocks (ORM, Swiftmailer, etc.)


Directory Structure:

By default Symfony consists of the following directories,

  • app/: The application configuration
  • src/: The project’s PHP code
  • vendor/: The third-party dependencies
  • web/: The web root directory

app/

‘app’ directory in Symfony 2 holds the application configuration. You can find all configuration-related stuff in the ‘app/config’ folder. If you need to configure your database or Swiftmailer then you will need to change parameters/settings from here. Apart from that this directory holds the ‘cache’. While writing code in Symfony 2 you will be working with lots of files ranging from XML, yml to PHP, twig, HTML, etc. Controllers will be written in some files, routes will be defined in another file, views will be written in some other file, and so on.

So while serving requests Symfony has to read all these necessary files. Since the count of files is too high, to achieve great performance Symfony 2 has inbuilt caching. And this cached data will be stored in the ‘cache’ directory. Again there is a ‘log’ directory that has debugging-related data, especially useful in development.

Apart from all these directories, the ‘app’ directory also holds, ‘AppKernel.php’. This is nothing but heart of Symfony 2 in other words this file is the entry point for any Symfony 2 project.

bin/

By default, this folder has some security check functions. We can use this directory the same as the ‘vendor’ directory.

 

src/

Again the most important directory in Symfony 2. This directory will be holding the source code of your app. You have to create controllers, views, and routes in this directory only. All of your PHP and template-related files will be residing in this directory. Symfony 2 follows a ‘bundle system’. There is a good explanation of this bundling system in Symfony 2 docs, you can read it here.

 

vendor/

‘vendor’ directory holds all third-party dependencies. To install and manage dependencies you will need ‘Composer’. Most commonly you will be using ‘doctrine’ for database-related things and ‘twig’ for template/views-related things.

web/

‘web’ directory is the webroot of your Symfony 2 project and will be used to store static data like images, and CSS of your app. This directory has two important files ‘app.php’ and ‘app_dev.php’. ‘app.php’ will be used in the production environment while ‘app_dev.php’ will be used in the development environment. In Symfony 2 you have to pass all requests to these files to boot up Symfony and get your work done.

These files will internally load the whole Symfony for you, will look up routes, will execute associated controllers, will generate the view, and will display your results. Apart from that, the ‘web’ directory has some general-purpose files like robots.txt, favicon, and apple icon.

In the root directory, you will find a file named ‘composer.json’. This file is used to hold the composer configuration. You have to edit this file to add, modify or remove third-party dependencies.

Apart from that, there are some read-me files in the root directory. If you want, you can read them else just forget about them.


Features:

It was built in order to fulfill the following requirements:

  • Easy to install and configure on most platforms (and guaranteed to work on standard *nix and Windows platforms)
  • Database engine-independent
  • 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
  • Easy to extend, allowing for integration with other vendor libraries

Installation:

You can follow below video for the installation guide:

Conclusion:

Symfony is a powerful and flexible PHP framework that can be used to develop a wide variety of web applications. If you are looking for a framework that can help you to increase your productivity, improve the quality of your applications, and reduce the costs of development and maintenance, then Symfony is a great option.

I Hope this article helps!