Code snippets

You will find here 113 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 use the Symfony string component to get the singular or plural of a word. It isn't easy to do this as th...

Symfony

Published on 2022-10-15 • Modified on 2022-10-15

 View the code


This snippet shows how to generate a slug with the Symfony string component. Usually, when using the Symfony string component, we ...

Symfony

Published on 2022-10-11 • Modified on 2022-10-11

 View the code


This snippet shows how to select an invalid choice value of a select form field in a Symfony functional test. Indeed, if you try t...

Symfony

Published on 2022-08-19 • Modified on 2022-08-19

 View the code


This snippet shows how to get the id of a Symfony form inside a Twig template. This is useful when wanting to give a particular at...

Symfony

Published on 2022-08-06 • Modified on 2022-08-06

 View the code


This snippet shows how to use the PHP compact function with the Symfony debug functions. Symfony dump() and dd() functions are gre...

Symfony

Published on 2022-06-30 • Modified on 2022-06-30

 View the code


In this snippet, we see how to test a role of an arbitrary user with Symfony. We know to do it for the current user, thanks to the...

Symfony

Published on 2022-06-12 • Modified on 2022-06-12

 View the code


This snippet shows how to fetch a Doctrine entity from a repository with the correct type hint. We can use the find() function to ...

Doctrine

Published on 2022-05-14 • Modified on 2022-05-14

 View the code


This snippet shows how to check if a string contains another string with PHP. This is a kind of tribute to our "old" PHP. The str...

PHP

Published on 2022-04-15 • Modified on 2022-04-15

 View the code


This snippet shows how to get the IRI of an entity with API Platform (and the opposite!). I have added this snippet because I noti...

API Platform

Published on 2022-03-14 • Modified on 2022-03-14

 View the code


This snippet shows how to cache data with Symfony. This one is for me because I always forget how to do. We have to inject the Cac...

Symfony

Published on 2022-03-13 • Modified on 2022-03-13

 View the code