Snippet: Symfony Forms - Accessing the Object in a Form

Perusing my Google Analytics data shows up some interesting results. For starters the top search query which sends people to my blog is "symfony accessing object in a form". This has been consistent for several months, but there is no article on my blog which answers that question. I imagine…

Snippet: Symfony Forms - Definition List Form Formatter

Back in April I posted a Snippet on Symfony Form Formatters. Since then I've done a bit more work with them and thought I'd share my custom form formatter for displaying forms as definition lists. Forms are often marked up as unordered lists, but with their label-input structure I find…

Symfony: What is it good for?

Symfony is one of my favourite bits of technology. I've got plans to write several articles and tutorials on it, but as I know many people haven't yet heard of it, or are unaware of how it could help them, I thought it best to write an introductory article. So,…

Snippet: Symfony Forms - Setting the Form Formatter

By default Symfony displays forms in tables, with each new input being a table row. If you want to display your forms more semantically with fieldsets and lists, Symfony has a list formatter built in. You can tell an individual form to display as a list using the code below.…

Snippet: Symfony Forms - Setting Default Values

I often forget how to set default values for form fields. Mainly because it's a function of sfForm rather than sfFormField I think. In the snippet below 'field' you are setting the default value for, and $value should be the default value. <?php // lib/form/MyModelForm.class.php public…

Snippet: Symfony User - Access the User Object

The following snippets provide access to the Symfony User object from various parts of a Symfony project. Template / View $user = $sf_user; Model or Form $user = sfContext::getInstance()->getUser(); Note: the context isn't setup when using the command line, therefore if you use this in the save() method…

Snippet: Symfony Forms - Allowing Extra Fields

Place this line of code in the configure method of a Symfony form to allow the saving of additional fields. This is used when additional information or inputs are needed in the form which are not saved in their own fields in the database. Examples are data which might be…