Symfony framework: what, why and how?

As a full-stack developer, what you look forward to the most is to find solutions to cut down on the amount of code which leads to saving a lot of development time. In my opinion, there is no better way than using a framework. Making the right choice is even better. 

For PHP technology, Symfony framework, sponsored by SensioLab, is the one you should put on top of your list.

What is Symfony framework?

Symfony is both a PHP framework and a collection of PHP components for building websites which supports the most databases out of the popular PHP frameworks.

The best way to interact with your databases is via the Doctrine ORM which Symfony uses to map objects to the database. This keeps your object model and the database schema separate, meaning that if you change a database column you don’t need to make many changes in your codebase.

Symfony follows the Model View Controller (MVC) design pattern which separates the manipulation of data from its presentation.

(Image source: Wikimedia Commons)

Why is Symfony a good choice?

Great performance

Symfony doesn’t require a lot of resources to run efficiently and also consumes less memory while still allowing the development of applications at high speed.

Fast development

Symfony has a lot of built-in functions which helps you not to write everything from scratch. That saves you a huge amount of developing time.

Flexibility and Expandability

Symfony will ask you to use very needed functionalities instead of tying you into its own ones. You can integrate a lot of packages with their own functionalities without reconfiguring everything from start by using a few command lines. This adaptability helps us speed up the pace of development.

Stability and Sustainability

Developed and sponsored by SensioLabs, Symfony framework is offered 3-year support for all the major versions. Moreover, SensioLabs also provides lifetime support for security-related issues and offers official tutorials and certification.

Good documentation and large community

Symfony has good documentation which helps you to get started easily and a large, vibrant community which is a passionate group of more than 600,000 developers in more than 120 countries, is also able to assist you when you run into difficulties.

References

Many sites and applications are using Symfony because of its sustainability and compatibility. Facebook Ads, Spotify, Dailymotion and Trivago are significant examples

How to use Symfony framework?

You can easily find the answer in Symfony Document for creating a new application, setting up an existing project or implementing Symfony Docker integration. What I am writing here is basically the steps to install a new application using Symfony framework version 6 on Ubuntu 22.04 operation system.

Prerequisite

  • Install PHP 8.1 or higher and these PHP extensions (which are installed and enabled by default in most PHP 8 installations): Ctype, iconv, PCRE, Session, SimpleXML, and Tokenizer;
  • Install Composer, which is used to install PHP packages.
  • Install Symfony CLI

Before creating new project, you can check if your system has enough requirements to run Symfony framework by running a command line in your command prompt:

symfony check:requirements

Congratulation to you if you receive a screen block like below

[OK]
Your system is ready to run Symfony projects

Otherwise, you will see what you need to install to match all requirements.

Creating new project

Run below command line in your command prompt:

symfony new my_project_directory --version="6.2.*" --webapp

Notes: Flag `– – webapp` will build you a traditional web application. You don’t need it if you are going to build a microservice or API.

Running Symfony project

Open your terminal. Negative to your project directory and run the below command to start Symfony application.

symfony server:start

Then, open your browser and access to http://localhost:8000/. The welcome page will be shown if everything is working.

You can stop the server by simply pressing Ctrl + C from your terminal.

Installing Packages

As a PHP developer, you might be know about steps to integrate a new library into your project. Sometimes, you have to put a bundle of code. But, with Symfony, that’s much quicker by running a single command line in your terminal.

For example, you’re gonna to install the most popular PHP logging library, Monolog, to create and store log messages in a variety of different places and trigger various actions.

composer require symfony/monolog-bundle

Security Vulnerabilities

With a simple command line, you can see compromised dependencies to replace or update.

symfony check:security

To get the most out of Symfony framework, and avoid disappointment, make sure that you have a decent knowledge of PHP and understand the underlying concepts behind frameworks: MVC architecture, object-oriented syntax, databases and ORMs, and the command line.

Hopefully, this article has helped you to figure out the coolest points of Symfony framework. 

Would you like to read more articles by Tekos’s Team? Everything’s here.

References:

https://symfony.com/doc/current/index.html

https://kinsta.com/blog/php-frameworks/

https://www.netsolutions.com/insights/symfony-framework-features

Author

Tommy Avatar

Leave a comment

Your email address will not be published. Required fields are marked *

Comment
Name
Email
Website

Skip to content