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…
Articles tagged with "Symfony"
Force URLS to use HTTP or HTTPS in Symfony 2
Creating a Crawler in Symfony 2 Using the DomCrawler and Client
There have been a few times where I have needed to crawl a Symfony 2 site to index pages and execute code so I built a crawler console command designed using the Symfony 2 DomCrawler and Client. This is a fun alternative to using curl, and the client offers plenty of browser-like features that come in handy 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…
Create a Custom Form Field Type in Symfony 2
The form builder in Symfony 2 is very flexible and has dozens of field options, but there will inevitably come a time when you need to create your own custom form field. The Symfony Cookbook has a great article on how to create a custom form field type and use it in your project. 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
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.
Define a Symfony 2 Form as a Service
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…
- 1
- 2