Symfony

Symfony – Debug the value of an environment variable

panneau de commande ancien avec des interrupteurs

In Symfony you can define some configuration in the .env file. To be sure of the value the program actually receives at runtime, there is the following command php bin/console debug:container –env-var=DATABASE_URL –env=test With this command you can easily see the value Symfony uses php bin/console debug:container –env-var=DATABASE_URL Symfony Container Environment Variables ======================================= // Displaying … Read more

Read the article →
Symfony

Symfony – Doctrine – How to see where an SQL query is executed

loupe posée sur des cartes postales anciennes

When using Doctrine, it is sometimes important to find where an SQL query is executed. Just turn on profiling_collect_backtrace on the connection, in the development configuration (config/packages/dev/doctrine.yaml): doctrine: dbal: connections: default: profiling_collect_backtrace: true Keep it for development only: collecting the call stack on every query is expensive. It relies on profiling, which is on by … Read more

Read the article →
Symfony4

Symfony4 how to create a custom error page 404

panneau « Dead End » au bout d'une route enneigée

You have to start by installing the necessary bundle: composer require symfony/twig-pack When done, create the template error404.html.twig templates/ └─ bundles/ └─ TwigBundle/ └─ Exception/ └─ error404.html.twig Example of the error404.html.twig template {% extends ‘base.html.twig’ %} {% block body %} <h1>Page not found</h1> <p> The requested page couldn’t be located. Checkout for any URL misspelling … Read more

Symfony4

Upload multiple files to an entity with Symfony4 and VichUploaderBundle

pile de plaques de carton ondulé

Preparation   To begin with, we need a Product entity as well as a ProductImage entity that will contain the names of the images. To do this, we use the command in our terminal VichUploaderBundle Setup As stated in the Symfony 4 documentation, we will use the VichUploaderBundle Then add the necessary “config/packages/vich_uploader.yaml” configuration file … Read more

Read the article →
Symfony2

Symfony – debug a Twig template with dump()

nervures d'une feuille verte en gros plan

Twig’s {{ dump() }} function is very handy to inspect a variable inside a template. But without the right package installed, the output is unreadable. Here is how to get a clean, collapsible display like this one: Install the DebugBundle The nice output comes from Symfony’s VarDumper component, enabled by the DebugBundle. Install it as … Read more

Read the article →