Exposing Configuration in Symfony 2 Bundles

In Symfony 2 there are two main ways to define configuration options for a bundle. The first way is to simply define parameters in the service container and the second is to expose semantic configuration for your bundle. more…




How to View Text that is Run Through the Symfony 2 Translator by Highlighting Translations

The Symfony 2 translator does a great job at translating text but there is not a great way to quickly see what text in a project is translated, especially when it could be translated by Symfony internally, in a model file, in a controller, in a twig template, etc. Given all of the different options, how could you quickly confirm text is running through the translator, and running through the translator only one time, so you don’t end up double translating text. more…



Override Symfony 2 Form Element Twig Template

It is possible to change the way a form element is rendered in a Symfony 2 project by overriding the Twig template. You can do this on a per-form basis by including the form element’s block right in your view, or you can make the change application-wide. more…


Create an Authentication Listener in Symfony 2

It is possible to subscribe to many events in Symfony 2, and login events are no different. You may want to have an authentication listener that increments a user’s failed login attempts so an account can be locked or you may want to set the last login date for a user on a successful login. more…


Change the Symfony 2 Validator Translation Domain and File Path

Change the translation path for the Symfony 2 validator

By default, the translation domain for the Symfony 2 validator is ‘validators’ and the translations are stored in the resources/translations/validators.<locale>.xliff files. In some applications it might be nice to use the same translation file as the rest of the site translations for validation messages, rather than using a separate validation translation file. Symfony makes this easy by setting a single parameter.

more…


Define a Symfony 2 Form as a Service

Register a form as a service in Symfony 2

If you use the Symfony 2 form builder and create your form types as classes then you may already know that you can define those form types as services and call them in your controller. That process is well documented in the The Book, and works very well. I have an alternative solution more…


Adding an AJAX Login Form to a Symfony Project

Adding an AJAX powered login form to a Symfony 2 project is pretty simple, but there are a few things to cover. The first is that the Symfony firewall handles authentication by sending a form to the route defined in the app/config/security.yml as the check_path for the firewall. So to login using AJAX, a form needs to be posted to that route along with a few fields, _username, _password, _remember_me, and if you’ve enabled CSRF for your form, the _csrf_token, field. more…