A bundle to manage options

0.3.1 2017-09-19 13:32 UTC


SensioLabsInsight Packagist


please use composer with

composer require creavo/option-bundle

Add the bundle to your app/AppKernel.php with

class AppKernel extends Kernel
    public function registerBundles()
        $bundles = [
            new Creavo\OptionBundle\CreavoOptionBundle(),
        return $bundles;

Update the doctrine-schema - use

php bin/console doctrine:schema:update

or do a migration:

php bin/console doctrine:migration:diff
php bin/console doctrine:migration:migrate


add the following lines to your app/config/config.yml:

    fetch_all: false
    simple_cache_service: null
  • fetch_all: true/false - when true, all settings are fetched from the database on initializing the bundle - depending on your use-case it might be more efficient to fetch all settings in a single query instead of fetching them later, when used (which leads to more queries)
  • simple_cache_service: inject a simple-cache here (something that implements Psr\SimpleCache\CacheInterface) - when null an ArrayCache for the request is used


as service

set a setting

$container->get('crv.option')->set('option-name', $optionValue, $optionType, $section);

get a setting (cached):


get a setting (uncached - will fetch value freshly from database without the cache)


in twig

to get a value in twig use

{{ crv_ob_setting('option-name') }}

use console-commands

set a setting with php bin/console crv:ob:set name value [type] [section] type and section are optional - if you omit them, the type will be a string and section null.

$ php bin/console crv:ob:set test1 "2017-09-16 12:00:00" dateTime parameters

setting the hash of the last-commit

php bin/console crv:ob:set app_version `git rev-parse --short HEAD`

to get a setting use get:

$ php bin/console crv:ob:get test1
| Element   | Value               |
| name      | test1               |
| type      | dateTime            |
| section   | parameters          |
| updatedAt | 2017-09-16 12:30:17 |
| value     | 2017-09-16 12:00:00 |