4 min read

Introduction to Symfony PHP framework

Do you want to learn the PHP Symfony framework but don't know where to start? This article introduces you to the Symfony framework.

I get a lot of requests from people asking me what Symfony is. Usually, I respond with; “Symfony is a full-stack PHP framework that uses a set of reusable components”. Whether you’re a junior or senior developer, it costs a lot of time to create an application from scratch every single time, and that’s where Symfony comes into play.

When working with a framework such as Symfony, the following three points are the biggest advantages of it.

  • Faster Development
  • Use of Components
  • Reuse pieces of code

When to learn Symfony

Make sure that you have a bit experience with front-end technologies like HTML5 and CSS3. JavaScript is not a must, but would make everything a bit more interactive and better looking if you do got experience with it.

For you back-end skills, make sure that you have an outstanding understanding of procedural PHP, and a decent understanding of Object-Oriented PHP since terms such as extends, classes, interfaces, objects, scope and accessibility will be used quite a lot.

The most important thing will be MVC. You don’t need to create an MVC structure with your eyes closed (we got Symfony for that) but you do need to know the concepts behind it.

Symfony coding standards

Every single programming language has its own set of coding standards. Most of them will be equal to another, but there are some slight changes here and there. Luckily, Symfony created their own coding standards which you can find right here. I recommend you to quickly scroll through them and see if you find something that you have not seen before.

Why should you use a framework?

Early in the days, web development looked completely different. Next to the components, developers used to be responsible for writing the code for the business logic as well. Most of you probably know that there are many frameworks and libraries available which will make it a lot easier to code, but it was not always like that.

With PHP, you will be using a lot of components and packages. Frameworks like Symfony and Laravel, prepackage a collection of third-party components together, which will eventually be a custom framework. What will that be? Think about things like:

  • Configuration files
  • Service providers
  • Prescribed directory structures
  • Application bootstrap

All these topics will define the benefit of using a framework, since someone else has already made decisions not just about individual components for you, but also about how those components should fit together.

Let’s look at it the other way around. Where would you start yourself if you have to create a framework yourself? Probably somewhere with the route HTTP request, right? Since you need to evaluate all of the HTTP request and response libraries available, and pick the right one. Then what? Well, you need to pick a router, followed with a route configuration file. Where will you be storing these files? And do not forget, where does the Controller fit? All these questions, are answered when you start using a framework.

MVC Explained

In coding, MVC is a design pattern, or better to say a software architecture which stands for Model View Controller. Like I have mentioned before, Symfony uses MVC. When using MVC, you will structure your application by separating the domain, application, and business logic from the rest of the user interface.

Model

The model layer manages the fundamental behaviors and data of the application. It will interact with the requests, respond to instructions, and even notify observers in event-driven systems.

View

The view is basically the user interface of your application. What using applications that uses MVC, you will be pulling data from the database in the model based on a request from the Controller, and translate it into data that you can use inside the view.

Controller

The Controller will take HTTP requests, so user input from the browser, gets the right data out of the database, validates the user input, and eventually sends a response back to the user.

In the model, you don’t want to use View or Controller code. The other way around as well. You don’t want to perform SQL queries inside your controller, let alone in your view.

All these components, are defined as the MVC design pattern. In my personal opinion, Symfony is huge because it’s using the Model View Controller design pattern. Well, I need to rephrase that, because Symfony contains MVC, but does not constrain it.

Conclusion 🚀

I hope that this article gave you a clear understanding of what Symfony actually is.

If you did enjoy reading this post and you want me to create an article on a topic you like, please send an email to info@darynazar.com.