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.
Also interesting
Expand your knowledge with the 4BIS Blog...
Automate, Web development, Software Modernisation, Business software, Knowledge Base
Discover how automation of your software and processes can improve your business. Learn about the benefits of automation and how it can make your operations more efficient. Contact us for customized automation solutions.
Read moreAutomate, Web development, Software Modernisation, Knowledge Base, WordPress, WooCommerce
Learn how to change backend behavior on a WordPress website for mobile devices with 4BIS Innovatives' expert guide. Discover tips on optimizing your WordPress site's performance by adjusting backend settings specifically for mobile users. Explore how...
Read moreBusiness software, Web development, Software Modernisation, B2B
Discover why HR software is essential for your company. Learn about its benefits and how custom solutions can transform your HR management. Contact us for tailored HR software solutions.
Read more 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!