dhorchler/config-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Database-stored settings that are administrable in Sonata Admin Bundle.

dev-master 2014-11-22 15:57 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:24:07 UTC


README

#Information

Compatible with Symfony 2.5 (under construction)

DHorchlerConfigBundle stores configuration settings in an ORM database and makes them administrable in Sonata Admin Bundle. These settings can be used anywhere in your project and can be modified at runtime by a Sonata admin user.

#Features:

  • individual validations for different data types
  • individual constrains with easily customizable error texts
  • jQuery supported form field default values

###Currently supported data types: string, integer, float, date, datetime, choice, multiplechoice.

#Installation

##Get the bundle

Let Composer download and install the bundle by first adding it to your composer.json

{
    "require": {
        "dhorchler/config-bundle": "dev-master"
    }
}

and then running

php composer.phar update dhorchler/config-bundle

##Enable the bundle in app/AppKernel.php

public function registerBundles() {
    $bundles = array(
        // ...
        new DHorchler\ConfigBundle\DHorchlerConfigBundle(),
    );
    // ...
}

##Create the settings table

You can do this by calling

php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate

or

php app/console doctrine:schema:update

or how ever you like.

#Configuration

In your app/config/config.yml add

sonata_block:
    default_contexts: [cms]
    blocks:
        sonata.admin.block.admin_list:
            contexts:   [admin]
        sonata.block.service.text:
        sonata.block.service.rss:

sonata_admin:
    title:      Sonata Project
    title_logo: /bundles/sonataadmin/logo_title.png
    templates:
        layout:  SonataAdminBundle::standard_layout.html.twig
        ajax:    SonataAdminBundle::ajax_layout.html.twig
        list:    SonataAdminBundle:CRUD:list.html.twig
        show:    SonataAdminBundle:CRUD:show.html.twig
        edit:    DHorchlerConfigBundle::edit.html.twig
    dashboard:
        blocks:
            - { position: left, type: sonata.admin.block.admin_list }
            
services:
      sonata.dh.admin.settings:
        class: DHorchler\ConfigBundle\Admin\ConfigAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: 'settings', label: Settings }
        arguments:
            - null
            - DHorchler\ConfigBundle\Entity\Settings
            - DHorchlerConfigBundle:Admin

After all this start managing your settings from the Sonata Admin backend.

#Usage example:

$this->em = $this->getDoctrine()->getEntityManager();
$settingsRaw = $this->em->createQueryBuilder()
    ->select('s.name, s.currentValue')
    ->from('DHorchlerConfigBundle:Settings', 's')
    ->getQuery()
    ->getResult();
foreach ($settingsRaw AS $setting) $settings[$setting['name']] = $setting['currentValue']

#Preview:

Screen shot list settings

Screen shot edit integer settings

Screen shot edit date settings

#Todo:

  • add more tests
  • client side validation