Symfony Components, the building blocks of the future!

Symfony Components are separate PHP libraries that can be used for multiple applications. These Components are so well written that they have become the foundation upon which the best PHP applications can be built. These components can be installed with composer. Composer is a dependency manager for PHP. This is the best way to keep track of all your dependencies.

Earlier we published an article about Symfony, referring to the Symfony Components. In this article I will tell you more about this.

The Symfony Components are a number of separate reusable PHP libraries. These Components are so well constructed that they have become the foundation on which the best PHP applications can be built.

The Symfony Components can be installed via Composer.

Composer is a dependency manager for PHP. Composer takes care of all the dependencies in your project for you. It neatly retrieves all the components you need for your project and all the libraries on which that component depends.

Package management is a well-known concept and much of composer is inspired by npm van Node.js and bundler of Ruby

However, now there are too many Components to cover them all, so we have selected the following: Asset, Config, Routing, Webpack Encore.

Asset Component

$ composer require symfony/asset

The Asset component takes care of things around creating URLs and versions of your so-called 'assets', such as your CSS and your JavaScript files.

In the past, the assets in a web page were often used in the following way:

link rel=”stylesheet” type=”text/css” href=”/css/main.css”

This approach is actually only recommended for small applications, hard-coding the URLs can quickly lead to irritation and problems.

For example, you have to type out the entire path for each asset. With the Asset component you can put assets in one package and distribute it. When moving an asset, you have to adjust all links and make sure you haven't forgotten any. In the Asset component you can easily change the location by changing the path of the package.

Config Component

$ composer require symfony/error-config

The Config component lets you search, combine and validate files of all kinds of file types.

Often if you have a PHP project that requires you to work with multiple services, it can be difficult to deal with all these different types of configuration files. With the Config component in Symfony this becomes a lot easier and saves you a lot of time.

Routing Component

$ composer require symfony/error-config

Het Routing component in Symfony is misschien wel de mooiste die er is. Het zorgt ervoor dat er aan de hand vaan een URL, bijvoorbeeld: /profiel/wijzigen/, een actie in de Controller (van het MVC model) kan uitvoeren. Dit betekent dat je ook SEO-friendly URL’s kan maken.

The URL is indicated above the method, also a name is indicated so that you can also use it in twig files.

With this component you can also specify the HTTP method so that the URL listens to it. If you don't specify anything then the URL will listen for any HTTP method (GET , POST, PUT, etc.)

In addition, there are many other great functions in this component, such as generating URLs, working extensively and smartly with parameters and sub-domain routing.

Webpack Encore

$ composer require symfony/webpack-encore

Webpack Encore is an easier way to get Webpack into your application, it allows you to bundle your JavaScript modules through an API, compile and minify your CSS and JS files.

In your webpack.config.js file you do the configuration for Webpack and Webpack Encore.

After configuring your files, you can run commands in the console to build assets. For the development environment you run the command:

$ yarn encore dev

This will then build the files and use them in a readable way, making it easy to debug your code in the Dev Tools in the browser.

For the production environment you can use this command:

$ yarn encore prod

This will optimize and minify all files to work as well as possible on the live application.

Read some of our blogs down here!

Expand your knowledge with the 4BIS Blog...

No secure server connection: These are the most common connection errors

Knowledge Base

Error messages when looking up a website are common. Although they are often easy to solve, they still often go wrong. This could be due to a small error, but this can immediately prevent a connection error. Resolving these errors requires some steps....

Read more

Domain Name Sales Software: This is How This Comes in Handy

Digital Marketing, Knowledge Base

Domain name sales software is indispensable if you want to sell domains. Selling domains has become increasingly popular, with private domains being bought up and sold for a high profit. The easiest way to do this is with domain name sales software.

Read more

What is a widget?

Software Modernisation, Knowledge Base, React, Business software

Many people come across widgets, but they are not always clear. So many people wonder, what is a widget? We explain what exactly a widget is in this blog.

Read more

And what can we do for you?_

Do you want to know more or are you interested? Please feel free to contact us directly, by phone or via mail.
Or use one of our contact forms so that we can answer you as quickly and appropriately as possible can give. We would love to hear from you!

back to top