What is Symfony?
Introduction to Symfony:
We are going to cover some basic concepts regarding the development of web applications using Symfony.
Let’s begin by the very basics. Let’s see what is mean by web applications(Web Apps)
It’s basically software that works over the internet to which you access using a web browser. You have 2 sides –
There are a 1. client side and 2. Server Side.
1. Client Side: – Client-side is executed on the user’s computer. The languages used on that side are HTML, CSS, and JavaScript. It’s used to show the user what’s happening on the web application and to get the user inputs.
2. Server Side: – There are multiple languages you can use.
Throughout this article, we will be using PHP and Symfony framework for the database engine, we will be using MySQL.
Now, What is Symfony?
Symfony is a PHP framework and it’s a toolbox. It is not only that but also it is a methodology a way of creating your application so that its organised, stable and scalable and Symfony is also a community of the developers who created this open source framework. It also works on extensions and plugins for this framework.
The benefits of using Symfony framework is that it enforces best practices. It basically forces you to use a certain way of working to put your files in a certain folder. It’s all flexible, you can change as well but if you don’t want to change it you are forced to use a certain folder structure, that makes the code very organised.
It’s easy for other people if you need to collaborate with you to know where each thing is? So that you don’t have to worry about creating tools but you worry instead of just making your web application.
The code is easier to maintain and its all modular up to the point where the actual Symfony framework is applied within a Symfony application.
Some basic HTTP concepts that are the core concept of how Symfony works. The client-side makes a request to the server, the server does processing database queries and it sends back the response.
That’s the most important thing in a web application and it’s ridiculously simple but you are not going to believe how often developers forget about this and don’t think with this module in mind when they are making web applications.
The usual flow when it comes to Symfony is firstly the request from the client and it has the main name and it will have some URL afterwards. This URL part is called Roots in Symfony.
Through the front controller application the PHP will get this request then it will be sent to the Kernel which is the heart of the Symfony application.
In the Kernel libraries are loaded and a few other configurations related things happen but your Routes, in this case, will be taking care of by the routing engine.
Start route is fine, it will point to a certain controller, controller file. And in Symfony actions are basically methods inside the controller. You can point to it using routes.
Always in single of this cycles, the action has to return a response object and that will eventually respond and will send back to the client and response can be in HTML, JSON, XML, image files, anything you can think of. But this is the way it flows.
Some more concepts:-
In Symfony, everything is a bundle. Bundles are the way that’s how the plugins are called, Modular pieces of code that have there own functionality. So all the code you created would be inside of bundles. Libraries are put in bundles as well. Even the actual Symfony library is treated as a bundle.
The Templates:-
Where the views are stored to show the user these views can be PHP views or they kind of use other language called twig which is a templating language. You can work in different environments within Symfony and that has to do with loading different configuration files. Two of these environments are the Development and Production. They are also testing environment and you can create your own environments too.
When you are developing your usually used developments environments and that still have the configuration that will make development easier. The cage will be revealed each time so you are going to always see the latest things and you will also going to have like a debug toolbar that can help you out with something.
There is a concept of services:-
Services are libraries that you can inject within your code. But they are not always loaded. You are injecting them and that’s called dependency injection. You inject them when you need to use them. And Symfony creates cage as well so in production environment putting up something is a lot faster.
Following is just an example of a template in a language called Twig
<! DOCTYPE html>
<html>
<head>
<title> Symfony Framework</title>
</head>
<body>
<h1> {{ Page Title}}</h1>
<table>
{% for user inusers%}
<tr>
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>{{user.phone}}</td>
</tr>
{%endof %}
</table>
</body>
</head>
</html>
This is how you will echo libraries and iterate variables and the advantage of the using twig is that it’s a lot cleaner than PHP. When you are using PHP templates, but its really up to you which one you want to use.
I prefer using twig. Databases are treated here with ORM which is a library, in this case, it is called Doctrine- Object Oriented. It’s optional you can use another ORM. If you want or you can not use one at all. I prefer using it because if I find it easier to maintain it is a bit work in general especially when you are working with other developers. It’s a lot easier when you use ORM and Doctrine also allows you to create an update your database using command line tools which are definitely powerful.
The configuration file for Symfony can be in different file format. Most of the formats are YML, XML, or just PHP classics throughout this article we will be using YML for the main configuration files and then when we get to choose we will choose Annotations, so you don’t have to change through different files that much.
But its really up to you again. So that’s one of the things about Symfony that is very flexible. You can adopt to the way that fits better with you, your own workflow.
Now where to get help:
Symfony.com official Symfony website has two awesome e books –
1. “The Book” – Which covers all the basics.
2. “The Cookbook” – Which has a recipe book which has different tips/things that you can do with Symfony.
3. There are google groups that you can write for support. If you need an answer to a question if you are running any issues and they will help you with it usually in minutes.
You will get an answer and there is an official forum as well.
So these are the basic concepts you need to keep in mind, before being looking at the code.
As a web designer and web developer your experience must have reached to new height, right? Further, you need to…
In today's digital landscape, timing is everything. Whether you're a social media manager, business owner, or content creator, the success…
Are you a website owner? Maintaining the website is the prime concern for any website owner. Yes, it’s equally important…
If you’ve planned to launch a WordPress website, you might get a question, “How do I log in to WordPress?”…
As the demand for virtual private servers (VPS) continues to grow, businesses and individuals are faced with a crucial decision:…