2017 © Pedro Peláez
 

symfony-bundle config-bundle

Settings from db

image

fg/config-bundle

Settings from db

  • Saturday, August 15, 2015
  • by fgursoy34
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

FgConfigBundle

This bundle helps you to store your settings for application layer. This settings are stored based on scope such as general, user groups, user and can be accessedfrom any layer later., (*1)

An example:, (*2)

Let say we have 30 quota available for Math class:, (*3)

{
    "id": 1,
    "scope_group_type": "labs",
    "scope_by_id": 2,
    "section": "registration",
    "name": "quota",
    "value": 30,
    "created_at" : "2015-08-13 00:00:00",
    "updated_at" : "2015-08-13 00:00:00"
}

1. Installation

1.1 Install Repository

You can install via composer., (*4)

composer require fg/config-bundle

or add to require section of composer.json:, (*5)

"fg/config-bundle": "dev-master"

1.2 Enable Bundle in app/AppKernel.php

public function registerBundles() {
    $bundles = array(
        // ...
        new Fg\Bundle\ConfigBundle\FgConfigBundle()
    );
    // ...
}

1.3 Run migration

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

2. Usage

2.1 Creating a ne setting

There are three different ways to create a new setting., (*6)

2.1.1 By using Command Line Interface (CLI)

You can create a new setting by runnig php app/console fg:config:create command from cli., (*7)

2.1.2 By calling create method of SettingService

You can create a new setting by calling the create method of SettingService which previously passed to service container., (*8)

$settingService = $this->get('fg_config.service.setting_service');
#create($name, $value, $scopeGroupType, $section, $scopeById = 0)
$setting = $settingService->create('test', 'test', 'general', 'general')

2.1.3 By using web user interface

http://localhost/path/to/management/setting, (*9)

2.2 Accessing

2.2.1 Accessing from controller layer

...
$settingService = $this->get('fg_config.service.setting_service');
$settingObject  = $settingService->getAllSettingByScope('quota', 'labs', 'registration', 2);
...

2.2.2 Accessing from Twig

...
{{ get_setting('phone') }} //get setting object of name phone
{{ get_setting_value('phone') }} //get value of name phone
...

The Versions

15/08 2015

dev-master

9999999-dev

Settings from db

  Sources   Download

MIT License

The Requires

 

by Fatih GÜRSOY

config symfony2 setting