Code Snippets
Symfony
Console commands and config you will need again in six months: security attributes, forms, Doctrine, and the APIs that quietly moved.
Symfony snippets, grouped by the part of the framework they touch.
Forms. Add an error from a controller when a check cannot be a constraint. Render a form field by field, and why form_rest matters. Format the collection prototype for fields users add and remove. Replace what a failed transformer shows with invalid_message. A card expiry month and year field without hiding a dropdown in CSS.
Security. is_granted in Twig takes more than roles, and the wrong attribute passes quietly. Leaving FOSUserBundle lists what replaces each piece.
Doctrine and requests. Knowing whether an insert or update worked, since flush() signals failure by throwing. Reading the current locale from a controller, a service and a template.
Search these 8 posts
Everything in Symfony

09/02/2026
is_granted in Twig: roles and IS_AUTHENTICATED
is_granted takes more than roles, and picking the wrong one gives you a check that quietly passes when it should not. What each attribute tests, why role hierarchy makes ROLE_USER true for your admins, and where the check belongs.

09/02/2026
Leaving FOSUserBundle: what replaces each piece
The bundle is maintained only enough for existing projects to migrate off it. Every piece it provided now has a replacement in Symfony itself or in two small bundles - and the migration is mostly deletion.

09/02/2026
Rendering a Symfony form field by field in Twig
One call renders the whole form and gives you no say in the markup. Splitting it up is four functions, and the one that matters most is form_rest - the safety net that stops a forgotten field from silently disappearing.

06/11/2015
Adding a form error from a controller in Symfony
Some checks cannot live in a constraint because they need something the form does not know about. FormError attaches the message to a field, or to the form itself, so it renders where the user is looking.

01/01/2015
Reading the current locale in Symfony
The locale lives on the Request, not in a global. How to reach it from a controller, from a service that has no request, and from a template - and where it is set before any of that.

11/19/2014
A card expiry month/year field in Symfony
The old answer was to render DateType's day dropdown and hide it with CSS. That works until somebody uses a screen reader. Two choice fields and a small transformer do the job honestly.

08/20/2014
invalid_message: what a failed transformer shows
A transformer that cannot convert what was typed throws, and Symfony turns that into a message the user reads. Left alone it says nothing useful; invalid_message is where you replace it.

11/19/2013
Knowing whether a Doctrine insert or update worked
Doctrine has no return value to check after flush() - it signals failure by throwing. Wrapping it is the right instinct, but the version of this snippet that has been circulating since 2013 catches nothing at all.