Musings of ErisDS
beta
ErisDS

Archive > Category > Symfony

Symfony is a PHP framework that I use regularly in my work and personal projects. It’s a fantastic tool for developing large websites and you’ll find some useful snippets & walk-throughs filed here.

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.

1
2
3
4
5
6
  <?php
    // lib/form/MyModelForm.class.php
    public function configure() {
      $this->widgetSchema->setFormFormatterName('list');
    }
?>

I often forget how to set default values for form fields. Mainly because it’s a function of sfForm rather than sfFormField I think. I the snippet below ‘field’ you are setting the default value for, and $value should be the default value.

1
  $this->setDefault('field', $value);

The following snippets provide access to the Symfony User object from various parts of a Symfony project.

Place this line of code in the configure method of a Symfony form to allow the saving of additional fields.

1
2
3
4
5
6
<?php
  // lib/form/MyModelForm.class.php
  public function configure() {
    $this->validatorSchema->setOption('allow_extra_fields', true);
  }
?>