foreverglory/setting-bundle

Symfony SettingBundle

v0.2.0 2016-03-19 10:27 UTC

This package is not auto-updated.

Last update: 2024-11-18 07:53:43 UTC


README

Symfony SettingBundle

Introduction

Composer

Add to composer.json in your project to require section:

{
    "foreverglory/setting-bundle": "~0.1"
}

Add this bundle to your application's kernel

//app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Glory\Bundle\SettingBundle\GlorySettingBundle(),
        // ...
    );
}

Configure service in your YAML configuration

#app/config/config.yml
glory_setting:
    driver:~    #default %database_driver%
    manager:~   #service id, default if driver is 'pdo_mysql', manager is @doctrine.orm.default_entity_manager
    model:~     #model class,default if driver is 'pdo_mysql', model is Glory\Bundle\SettingBundle\Entity\Setting

php code

$settingManager = $container->get('glory_setting.manager');

$settingManager->value('name');
$settingManager->value('name','default-value');

$settingManager->value('name.key');
$settingManager->value('name.key','default-value');

$settingManager->save('name','value');
$settingManager->save('name',array('key'=>'value'));

twig code

{# string #}
{{setting('name')}}
{{setting('name','default-value')}}

{# array #}
{{setting('name.key')}}
{{setting('name.key','default-value')}}

{% set value=setting('name') %}
{{value.key}}

{# Warning #}
{# 
    if setting('name') is array 
    use {{setting('name')}}
    will throw Exception("Notice: Array to string conversion")
#}