sfDoctrineSettingsPlugin - 1.2.4

Allows for settings to stored in the database and recalled for use in the application.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
Show source

Symfony Doctrine Settings Plugin

This plugin allows the easy use of a basic dynamic settings table. It will create sf_settings, and allow the use of an admin generator interface (via the sfSettings module) in order to add/edit/delete settings.

Since loading a setting requires a query to the database, performance ramifications are best mitigated by using sfSettings:load() to pre-load settings in the action for use elsewhere, i.e.:


sfSettings::load(array('setting1', 'setting2', 'setting3'));

If you have settings that you know you will want loaded by default for every action, you can put those in config/defaults.yml.

# /config/defaults.yml
settings: [ setting_name_1, setting_name_2 ]

However you will also need to add a filter to the chain so that your settings get loaded, i.e. the following lines at the top of appname/config/filters.yml:

# /apps/public/config/filters.yml
  class: sfSettingsFilter

After the settings have been loaded, they are stored in memory for retrieval by sfSettings::get() (returns a string value) or sfSettings::getSetting() (returns an sfSetting object)


A admin/backend module also exists for managing the settings in the database. you must enable the module in order to access it

# /apps/backend/config/settings.yml
     enabled_modules:        [default, sfSettings]


In order to use the WYSIWYG field you must install sfFormExtraPlugin as well as the TINYMCE editor. After your app.yml file to tell the plugin to use the rich text editor

# /apps/backend/config/app.yml
    rich_fields: false

Options Field for settings of types checkbox and select

When using the checkbox and select types you must use the options field to specify valid options for the value. The options field should be filled out as an arry in yaml format

# options field for types select and checkbox
value: 'The Label'
option2: 'Option 2'

New Types of Settings

If you would like to add more types of options to the sfSettingsPlugin you can override the $type_choices variable in your model.

# /lib/model/doctrine/sfSettingsPlugin/sfSettingTable.class.php
protected static $type_choices = array(
           'checkbox' =>  'Checkbox',
           'input'    =>  'Text Field',
           'textarea' =>  'Text Area',
           'wysiwyg'  =>  'Rich Text Area',
           'yesno'    =>  'Yes/No Radios',
           'select'   =>  'Select',
           'newCustomType' => 'New Custom Type',);

If you would like to set a custom widget for the value field when using this type make a new class in your project named sfSettingsSettingNewCustomTypeForm The example below is making the value field a Select box of choices from the options field

# /lib/form/sfSettingsSettingCheckboxForm.class.php
class sfSettingsSettingNewCustomTypeForm extends sfSettingForm
  public function configure()
    $choices = sfYaml::load($this->getObject()->getOptions());
    if ( is_array($choices) && count($choices) ) {
      $this->widgetSchema['value'] = new sfWidgetFormChoice(array('choices' => $choices));
      $this->validatorSchema['value'] = new sfValidatorChoice(array('choices' => array_keys($choices)));
    } else {


  • id
    • Used as the primary key
  • name
    • Used as the variable name
    • Must be unique
  • type
    • Used to decide what type of editor is needed in the sfSettings backend
    • Current Types
    • checkbox
    • input
    • textbox
    • yesno
    • select
    • wysiwyg
  • options
    • select
    • An array of options in yaml format
    • checkbox
    • An array of options in yaml format
    • wysiwyg
    • Will be appended to the text_area options after rich=true
  • value
    • The value of the setting