Ludovic Frank - Freelance developer

What is the Symfony framework and why should you use it for your next web project?

ionicons-v5-k Ludovic Frank May 21, 2023
103 reads Level:

Hello 🙂,

If you follow this blog at all, you'll know that I really like the Symfony framework. In fact, it's my preferred choice for all my projects (even this blog ...).

When you're doing web development, you'll probably have noticed that there's a lot of repetition. Imagine you want to create a simple web application that lets users create "to-dos" and save them - yes, it's a classic... ?

Before creating your to-do application, you'll need to (non-exhaustive list) :

  • Create your database and the SQL queries to use it.
  • Create a system for your users to create their accounts.
  • Create an e-mail system, to check that their e-mail addresses are correct.
  • Create a way for your users to connect to your web application.

These are just a few of the steps involved in creating your web application, and, as you'll agree, they add absolutely no value whatsoever. Indeed, these kinds of requirements are ultra-basic needs in any web site or application, and virtually every web site in the world has these basic needs.

Once your superb application has been launched, then you'll need to add new functionalities... for example, offering users graphics to give them statistics on "how many spots they've posted and when they posted them".Again, "creating a graph" is a "basic" task that many projects have to do, so why waste precious time doing it?

If what I'm talking about here speaks to you (that's a weird sentence), then this article is for you. We're going to take a look at what Symfony is and why it can make your life a whole lot easier....

Ready to get started? Let's get started.

What is Symfony?

Are you still here? Great, now that you're ready to dive into the world of Symfony, let's start with the basics. What is Symfony?

To cut a long story short, we could say that Symfony is an "open source" PHP framework. Yes, I agree that for the "uninitiated", this doesn't mean a thing... so let's explain:

well, if web development is a kitchen, Symfony is your personal world-class chef (yes, really, what do you mean I like Symfo?). It's a "PHP framework", a set of structured, reusable and maintainable tools for creating "high-end", scalable web applications. Symfony isn't just a tool; it's a complete toolbox packed with everything you need to make creating applications and websites a breeze (well, you're going to have to learn a few things first ... ? ? like being a developer).

The history and evolution of Symfony

Every superhero has a story, and Symfony is no exception. The brainchild of Fabien Potencier, Symfony was born in 2005 as part of the SensioLabs project, a French web agency. The "first cry" was heard in 2007 when Symfony 1.0 was presented to the world. Since then, like a fine wine, Symfony has only improved with age.

Symfony2 appeared in 2011, introducing a whole new way of developing web applications using reusable components. It's like going from making marshmallows over a campfire to a fully equipped barbecue. Suddenly, everything is at your fingertips, easy to use and easy to update (Symfony 1 and Symfony 2 are actually very different, as the recent versions of Symfony still have foundations that were laid in Symfony 2, Symfony 2 being the era when yours truly first got to grips with it).

Then Symfony 3 arrived in 2015, taking efficiency to another level, a bit like swapping your manual car for an automatic one. Symfony 4 arrived in 2017, Symfony 5 in 2019, followed by Symfony 6 in 2021.

Each version offering more streamlined processes, user-friendly interfaces and more application possibilities. It's as if someone had taken a "good framework" and kept pressing the "upgrade" button until it became "great"....

The main Symfony components

Let's take a look at this superhero's toolbox. Symfony comprises three main parts: Bundles, Components and Bridges:

  • "Bundles: Bundles are code snippets ready to be reused for different projects. They are similar to "plugins" in other ecosystems. Need to add user authentication? There's a bundle for that. Want to easily manage your content? Yes, there's a bundle for that too.
  • "Components: Components are like the Lego of Symfony. They are self-contained, reusable PHP libraries that you can use to perform specific functions, such as form creation, security, templating and so on. They're bricks you can assemble to create the castle or spaceship of your dreams... well, I mean, a great web application.
  • "Bridges: have you ever tried to connect two systems that simply refuse to talk to each other, like two stubborn goats on a narrow bridge? (That's where Symfony bridges come in. They connect Symfony with other software libraries, resolving incompatibility issues. No need for translators, Symfony bridges do all the work.

In short, Symfony is your all-in-one toolbox, a (strange?) symphony of code that streamlines and simplifies your web development journey. It's the personal chef you never knew you needed, the superhero you've been waiting for...

How does Symfony work?

The answer to this question is similar to the way an orchestra creates a symphony. You have all the parts - the violin, the cello, the flute, the drum - each playing its specific role, culminating in a melody that leaves the audience spellbound. So let's see how Symfony, our conductor, helps all these parts to play in harmony.

Symfony's structure

If you've ever tried to build something complex, like a model of a spaceship, you know that you have to follow the instructions patiently, one step at a time. In Symfony, the "instructions" are a set of best practices that you can see here.

Let's go back to the three elements we saw earlier, bundles, components and bridges:

  • Remember our friend the "bundle"? Each bundle in Symfony is a self-contained piece of code with a specific task. Think of it as a musician in our orchestra, with his own score and his own instrument. Bundles interact seamlessly with other bundles, making them incredibly modular. This means you can add, remove or replace them without disturbing the overall melody of your application.
  • The "components", our Lego, offer different functionalities. These range from HTTP message handling to file management, language translation and much more. It's as if each Lego brings a unique functionality to your project, and all you have to do is assemble them in the right order to bring your vision to life. You can also find Symfony components in other projects.
  • Finally, "Bridges" act as conductors, connecting different software libraries to Symfony, making sure that performance runs smoothly. They make sure your drummer and violinist (different software layers) are on the same wavelength, even if they've never played together before.

Simplify the web development process

Imagine sitting at your desk, faced with a mountain of code to write, knowing that you're essentially reinventing the wheel (remember my intro?). Isn't that crazy? Symfony transforms this mundane and repetitive task into a more creative and efficient process....

With Symfony, you don't have to write complex authentication systems from scratch for every new project. Instead, you simply use a bundle designed specifically for this purpose (it used to be the FoSUserBundle, and now it's directly in the MakerBundle). It's like buying a ready-to-assemble shelf instead of chopping down a tree to build one (afterwards, if you don't know what to do with your weekends...).

You save a lot of time and effort, and you're free to concentrate on the unique and exciting aspects of your project.

What's more, Symfony's MVC (Model-View-Controller) architecture separates the logic, user interface and control flow of your application. Imagine you're a painter and instead of having all your colors mixed together, they're neatly separated on a palette, ready to be used to create your masterpiece. That's what Symfony's MVC structure does to your code - it organizes it neatly for easy management and enhancement.

Although the framework is historically based on the MVC model, which is still used today, especially if you use Stimulus and Turbo, it is of course possible to create an API only with Symfony, notably via API Platform.

As far as I'm concerned, that's what I love about Symfony, I don't focus on things that ultimately don't interest me, the best example of which is my Symfony UX/Turbo application.

During its development, my only question was "how can I offer a crazy experience, whether for customers or for the restaurant owner", because in the end... that's all that matters.

Of course, there have been times when I've had to tweak things a bit more, but that's not a problem, as the documentation is very well done and allows you to get your hands dirty when necessary.

To date, this application has taken reservations from 10 or so thousand people, and will soon open up to other restaurants... I'm delighted with the feedback from customers: "It's friendly", "It's simple".

Yes, that's how it was conceived, all my attention and energy was focused on that, and at the end of development I took the time to optimize performance, but before that. I only thought about what really mattered, my customers.

And for that, thank you Symfony ❤️.

Why use Symfony for your web development projects?

It's time to take a closer look at what Symfony has to offer developers (like me)

The symphony of benefits

(No, I won't stop playing with words)

Efficiency

Remember those annoying repetitive tasks that make you feel like you're doing nothing? With Symfony, they're a thing of the past. Symfony takes care of all the mundane tasks, allowing you to concentrate on the more exciting aspects of your project. In short, Symfony is your King Arthur's Merlin, doing all the magic while you enjoy the show.

(For a more detailed example, see the last paragraph of the previous chapter)

Flexibility

Symfony's modularity is its greatest asset. Need to replace one bundle or component with another? Don't hesitate. Symfony is as flexible as a gymnast, allowing you to bend and twist your project to your heart's content.

Scalability

As your project grows, Symfony grows with it. Its design allows you to add more functionality without overloading the existing structure. It's like having a backpack that magically expands to accommodate everything you want to carry. And later, when your company is a multinational, you can break it all down into microservices, still using the same framework...

Real-world applications using Symfony...

We talk, we talk, but we want to create things, don't we? Take a look at which projects and companies around the world are using Symfony:

What do you mean the last four are my projects? I have no idea what you're talking about,

Symfony and other PHP frameworks

In the world of PHP frameworks, Symfony is not without competition. Laravel, CodeIgniter and Zend also have their fan clubs. But what sets Symfony apart?

Compared to Laravel, which is considered more beginner-friendly, Symfony shines for its extensive, mature ecosystem and greater number of reusable components. It's like choosing between a sports car and a utility vehicle. Sure, the sports car might be flashier, but the utility vehicle will take you places and enable more.

Against CodeIgniter, Symfony wins thanks to its active community and better coding standards. CodeIgniter may seem like the easy way out, but Symfony is the way to better code and more sustainable applications.

Finally, in the face-off with Zend, Symfony appears to be the most efficient and least complex option. Zend is like a huge toolbox with every possible tool. This may sound impressive, but when you're in a hurry, it's hard to find the screwdriver. Symfony, on the other hand, provides just the right tools in a neat, accessible package.

Symfony and Ruby on Rails

I had to tell you about them, because they're very similar. Ruby is, I'd say, more present on the North American continent, while Symfony is more European.

Ruby on Rails, often referred to simply as Rails, is based on the Ruby programming language and favors convention over configuration. It's user-friendly, efficient and packed with built-in functionality, like a musician who doesn't just play, but sings and dances. Rails is very popular for creating "Proof of concept (POC)", when you have an idea for a project and want to get it up and running quickly.

On the other hand, Symfony, our maestro in the PHP world, excels in flexibility, reusability and modularity, providing a robust environment for larger, more complex applications.

It's worth noting that the two frameworks resemble each other and, despite their similar philosophies, sometimes copy each other. For example, since the end of Symfony 5 and the beginning of Symfony 6, hotwired has been integrated into Symfony, bearing in mind that the origin of hotwired comes from our friends at 37signals, the creators of Rails.

Ultimately, the choice between Symfony and Rails depends on your project requirements, your comfort with PHP or Ruby, and the "specific melody you want your web application (or website) to play"!

That should make you want to dig even deeper into the subject, don't you think?

Conclusion

And that's it, the Symfony article has come to an end, I've tried to make it as entertaining as possible to get you interested in taking a look.

In a future article, we'll go a little further into Symfony? functionalities.

As for me, I'm going to keep playing with it, whether it's improving this blog, working on customer projects or launching side projects.

Have a great day!