A simple setting bundle for Symfony2

Installs: 96

Dependents: 0

Stars: 3

Watchers: 2

Forks: 1

Open Issues: 1

Type: symfony-bundle

1.0 2014-04-08 21:06 UTC


This bundle simply allow to manage settings in your application trough the database. That make it easier to manage during the application running than parameters files.

Build Status



"vbee/settingbundle": "dev-master"

Update your vendors:

php composer.phar update vbee/settingbundle

Update your configuration file: app/config/config.yml

    orm: doctrine # possible values = doctrine and mongodb


new VBee\SettingBundle\VBeeSettingBundle(),

Update the database:

php app/console doctrine:schema:update --force

Update route for access to the html interface:

    resource: "@VBeeSettingBundle/Resources/config/route/routing.xml"
    prefix:   /setting

    resource: "@VBeeSettingBundle/Resources/config/route/api.xml"
    prefix:   /api

Import css:

<link rel="stylesheet" href="{{ asset('bundles/vbeesetting/css/bootstrap.min.css') }}" type="text/css" media="all" />

Install assets:

php app/console asset:install

Usage in code

Create a new Setting

$this->container->get('vbee.manager.setting')->create('foo', 'bar'); // default type = 'str'
$this->container->get('vbee.manager.setting')->create('foo', 'bar', 'str');
$this->container->get('vbee.manager.setting')->create('foo', '123', 'int');
// ... check all available types

Get a existing Setting

// or

Get all Settings


Set a new value for a Setting:

$this->container->get('vbee.manager.setting')->set('foo', 'bar');
$this->container->get('vbee.manager.setting')->set('foo', 'bar', 'str');
$this->container->get('vbee.manager.setting')->set('foo', '123', 'int');
// ... check all available types

Remove a Setting


Usage in Twig

Get a existing Setting

{{ getSetting('foo') }}

Usage in command line

Create a new Setting

php app/console vbee:setting:create foo bar

Remove a Setting

php app/console vbee:setting:remove foo bar

Purge all Settings

php app/console vbee:setting:remove --all

Value Types

VBeeSetting bundle allow you to make validation on your setting value dynamically.

By Default, these types are available:

Type In DB In Code
String str VBee\SettingBundle\Enum\SettingTypeEnum::STRING
Integer int VBee\SettingBundle\Enum\SettingTypeEnum::INTEGER
Date date VBee\SettingBundle\Enum\SettingTypeEnum::DATE
Phone phone VBee\SettingBundle\Enum\SettingTypeEnum::PHONE
Url url VBee\SettingBundle\Enum\SettingTypeEnum::URL

Add a Type

Declare your type

your first have to declare your new type as:

# app/config/config.yml
        your: { label: setting_type.your }

you can use translation file for translate the label

# src/Acme/DemoBundle/Resources/translations/VBeeSettingBundle.[locale].yml
    your: "Your"

Create your validator

then you need to make your custom type validator

namespace Acme\DemoBundle\Validator\Constraints;

use VBee\SettingBundle\Validator\Constraints\SettingValueValidatorInterface;

class YourValidator implements SettingValueValidatorInterface
     * @param $value
     * @return bool
    public function validate($value)
        $matches = array(); preg_match('/^your(.+)$/', $value, $matches);
        if (isset($matches[0])) { return true; }
        return false;

    public function getName()
        return 'your';

finally, register it as service tagged by vbee.setting_value_validator

<service id="acme.validator.your" class="Acme\DemoBundle\Validator\Constraints\YourValidator">
    <tag name="vbee.setting_value_validator"/>


list setting

GET: /api/setting
    "status": {
        "code": 200,
        "message": "OK"
    "response": {
        "settings": {
            "foo": "bar",