Compatible with Symfony 2.5 (under construction), (*1)
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., (*2)
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., (*3)
Installation
Get the bundle
Let Composer download and install the bundle by first adding it to your composer.json, (*4)
{
"require": {
"dhorchler/config-bundle": "dev-master"
}
}
and then running, (*5)
php composer.phar update dhorchler/config-bundle
Enable the bundle
in app/AppKernel.php, (*6)
public function registerBundles() {
$bundles = array(
// ...
new DHorchler\ConfigBundle\DHorchlerConfigBundle(),
);
// ...
}
Create the settings table
You can do this by calling, (*7)
php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate
or, (*8)
php app/console doctrine:schema:update
or how ever you like., (*9)
Configuration
In your app/config/config.yml add, (*10)
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., (*11)
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:
, (*12)
, (*13)
, (*14)
Todo:
- add more tests
- client side validation