Posts Tagged: Symfony

Easiest Way to Customize a Symfony Form

Before I get started, I realize that Symfony has this entire form theming apparatus and it’s great. But this is a simple technique that puts the control of the form in the hands of the person laying out the HTML rather than the developer. All I do is when I’m rendering my form, I wrap… Read more »

Symfony ChoiceType Default to Checkbox Checked

I’m rendering a bunch of checkboxes using a Symfony form type of ChoiceType and I want some of them to be checked by default. It’s basically a list of transactions and the ones that fail will be checked so that the user can fix whatever caused the problem and run them failed ones again. It… Read more »

Symfony Load Twig Template From String

As is always the case with PHP, or open source technology, there’s a gazillion ways to rule the world, or solve a problem. I had a problem with a Symfony app I was building. I needed to load the Twig template from a string variable rather than a file. To do so is easy. All… Read more »

Symfony Doctrine To Flush or Not to Flush

I’m in the process of converting an old MySQL database to a shiny new MySQL database controlled via Doctrine. Some of the tables have tens of thousands of records in them, so I was curious if it made sense to flush after each insert, wait till the end and flush or flush periodically during the… Read more »

Customize Symfony Form Builder Error Message in Twig Template

I’m building a form to gather credit card information and I want to customize the error messages displayed on the form. I’m sure I can do this with form theming, and that’s great, but I just wanted a down and dirty, in the template, spitting out custom error messages solution. Of course, normally, I would… Read more »

Symfony Doctrine Event Listener Silently Fails on instanceof

If you’ve ever done this in a Symfony doctrine event listener if ($entity instanceof User) { // Do something for this particular entity } you might have run across this annoyance. If you forgot to add a “use” statement for your “User” entity in your event listener class, this check will silently fail. I think… Read more »

Symfony Error: Call to a member function format() on string

This Symfony error tripped me up for a few minutes today, it’s not particularly obvious what it’s referring to. Error: Call to a member function format() on string In my case, I was setting a Doctrine entity field to a string when it should have been a DateTime object. In my entity class I defined… Read more »