Code snippets

You will find here 234 code snippets I find useful so I don't have to Google ™ or Stackoverflow ™ them when I need. There are also code snippets I always forget! 😁 Sometimes, related links to the code will be available. The main difference with other random snippets you will find on the web is that in most cases (for the Symfony related ones) you will be able to run them directly from this website to check the output so you can verify it works as expected ™.

This snippet shows how to convert an array into an object with the Symfony serializer. That's a common need to denormalize an ar...

Symfony

Published on 2023-04-13 • Modified on 2023-04-13

 View the code


This snippet shows how to get all the routes of a Symfony application. Here, we display all the routes starting with blog_ which b...

Symfony

Published on 2023-03-31 • Modified on 2023-03-31

 View the code


This snippet shows how to create an event subscriber for a 404 NotFoundHttpException. Here, we test if a given path was accessed (...

Symfony

Published on 2023-03-30 • Modified on 2023-03-30

 View the code


This snippet shows how to execute a given Make target inside a target. When you want to run a target before another, you can put a...

make

Published on 2023-03-15 • Modified on 2023-03-15

 View the code


This snippet shows how to get the meaning of HTTP response codes with Symfony. It can be done with the help of the Response class ...

Symfony

Published on 2023-03-06 • Modified on 2023-03-06

 View the code


This snippet shows how to display a money amount with Twig. There's a filter for that, and it handles the current locale. The fol...

Twig

Published on 2023-02-25 • Modified on 2023-02-25

 View the code


This snippet shows how to get the name of a Twig template inside a Twig template. Yes, this is inception! Not so hard as there is...

Twig

Published on 2023-02-18 • Modified on 2023-02-18

 View the code


This snippet shows how to cache data with the Symfony CacheItemPoolInterface service. In a previous snippet, we saw how to cache ...

Symfony

Published on 2023-02-14 • Modified on 2023-02-14

 View the code


This snippet shows how to disable the translations for the test environment with Symfony. The goal is to test the translation code...

Symfony

Published on 2023-01-31 • Modified on 2023-01-31

 View the code


This snippet shows how to retrieving the attributes' parameters of a PHP class with reflection. As you can see, it's straightforwa...

PHP

Published on 2023-01-26 • Modified on 2023-01-26

 View the code