PHPackages                             lexxpavlov/settingsbundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lexxpavlov/settingsbundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

lexxpavlov/settingsbundle
=========================

Symfony2/3/4 Settings bundle provides flexible settings (Boolean, Integer, Float, String, Text, Html), easily configurable with Sonata Admin

1.5.2(5y ago)104.5k10[2 issues](https://github.com/lexxpavlov/LexxpavlovSettingsBundle/issues)MITPHPPHP &gt;=7.1

Since Mar 29Pushed 5y ago2 watchersCompare

[ Source](https://github.com/lexxpavlov/LexxpavlovSettingsBundle)[ Packagist](https://packagist.org/packages/lexxpavlov/settingsbundle)[ Docs](https://github.com/lexxpavlov/LexxpavlovSettingsBundle)[ RSS](/packages/lexxpavlov-settingsbundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (17)Used By (0)

LexxpavlovSettingsBundle
========================

[](#lexxpavlovsettingsbundle)

This bundle helps you to manage your settings in Symfony2/3/4 project.

Settings has one of types: Boolean, Integer, Float, String, Text, Html. You may get one concrete setting or fetch group of settings. Fetching of settings may be cached by your cache provider used in project.

Management of settings provides by SonataAdminBundle. In other case you may manage settings via code by use special functions or predefined forms.

Installation
------------

[](#installation)

### Composer

[](#composer)

Download LexxpavlovSettingsBundle and its dependencies to the vendor directory.

You can use Composer for the automated process:

```
$ composer require lexxpavlov/settingsbundle
```

or manually add link to bundle into your `composer.json` and run `$ composer update`:

```
{
    "require" : {
        "lexxpavlov/settingsbundle": "~1.2"
    }
}
```

Composer will install bundle to `vendor/lexxpavlov/settingsbundle` directory.

### Adding bundle to your application kernel

[](#adding-bundle-to-your-application-kernel)

```
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Lexxpavlov\SettingsBundle\LexxpavlovSettingsBundle(),
        // ...
    );
}
```

### Configuration

[](#configuration)

Bundle does not need any required parameters and will work without changes in `config.yml`. But you may config some parameters, read more below.

Now you need create the tables in your database:

```
$ php bin/console doctrine:schema:update --dump-sql
```

or in Symfony2:

```
$ php app/console doctrine:schema:update --dump-sql
```

This will show SQL queries for creating of tables in the database. You may manually run these queries.

> **Note.**You may also execute `php bin/console doctrine:schema:update --force` command, and Doctrine will create needed tables for you. But I strongly recommend you to execute `--dump-sql` first and check SQL, which Doctrine will execute.

> **Note.**If you use 1.1.\* version of bundle, you need to update database.

Usage
-----

[](#usage)

Use SonataAdminBundle for manage your settings. Otherwise use predefined forms. You feel free to use the bundle if you configure settings with database tool (phpMyAdmin or other) or by use special functions called in your code (see below).

You may put settings to group or not. Groups may be used for fetching several settings at one query.

Fetching of settings are supported in twig templates or in controller (or in any script where settings service are injected).

For example, you created 3 settings:

- `page_title` without group
- `description` and `keywords` in `meta` group.

##### Use in controller

[](#use-in-controller)

```
namespace App\YourBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class DefaultController extends Controller
{
    /**
     * @Route("/")
     * @Template()
     */
    public function indexAction()
    {
        $settings = $this->get('settings');

        $title = $settings->get('page_title');
        $meta = $settings->group('meta');

        return array(
            'title' => $title,
            'meta_description' => $meta['description'],
            'meta_keywords' => $meta['keywords'],
        );
    }
}
```

##### Use in template

[](#use-in-template)

```
{% extends '::base.html.twig'%}

{% block meta %}
{{ settings('page_title') }}

{% endblock %}
```

Advanced usage
--------------

[](#advanced-usage)

### Full configuration

[](#full-configuration)

Here is the default configuration for the bundle (all parameters are optional):

```
lexxpavlov_settings:
    enable_short_service: true  # default true, use false for disable registering 'settings' service
    html_widget: ckeditor       # default null, valid values are 'null', 'ckeditor'
    cache_provider: cache.app   # default null, for enable database caching set up name of caching service
    use_category_comment: false # default false, use category comment as its title in settings list (in SettingsAdmin)
    ckeditor:                   # set parameters of ckeditor. Not need if IvoryCKEditorBundle is installed
        base_path: /ckeditor/
        js_path: /ckeditor/ckeditor.js
```

`ckeditor` form type may be added by [IvoryCKEditorBundle](https://github.com/egeloen/IvoryCKEditorBundle). If you are using CKEditor without `IvoryCKEditorBundle`, you must specify the parameters `base_path` and `js_path`.

### Groups of settings

[](#groups-of-settings)

For fetch several of settings from one group you may use one of two cases:

```
$param1 = $settings->get('category', 'param1');
$param2 = $settings->get('category', 'param2');
// or
$cat = $settings->group('category');
$param1 = $cat['param1'];
$param2 = $cat['param2'];
```

Both of cases has an identical perfomance - the whole group will fetch while first access to it, fetching of data will be only one time.

#### Using default value in twig

[](#using-default-value-in-twig)

```
{% extends '::base.html.twig'%}

{% block meta %}
{{ settings('page_title', null, 'My default title') }}

{% endblock %}
```

#### Using groups in twig

[](#using-groups-in-twig)

```
{% set params = settings_group('category') %}

{{ params.param1 }}
{{ params['param-2'] }}

```

#### Example of using the settings group

[](#example-of-using-the-settings-group)

There is an example of group using - settings which used in backend and frontend. Several settings are placed in `client` group, and include to template:

```
{# app/Resources/views/base.html.twig #}

{# ... #}

{% block javascript_inline %}
window.settings = {{ settings_group('client')|json_encode(constant('JSON_NUMERIC_CHECK'))|raw }};
{% endblock %}

```

### Perfomance and caching

[](#perfomance-and-caching)

Use caching for increase of fetching settings. If you don't use caching already - it is perfect time to do! It's very simple!

```
# app/config/services.yml
services:
    cache.app:
        class: Symfony\Component\Cache\Adapter\FilesystemAdapter

# app/config/config.yml
lexxpavlov_settings:
    cache_provider: cache.app
```

The bundle will use registered service `cache.app` for cache data. Cache provider may be one of [Doctrine cache](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/caching.html) or [Symfony cache](https://symfony.com/doc/current/components/cache.html) - PSR-6 Cache (Symfony 3.1) or PSR-16 Simple Cache (Symfony 3.3).

### Arrange Settings admin group in SonataAdminBundle

[](#arrange-settings-admin-group-in-sonataadminbundle)

`SonataAdminBundle` arranges admin groups by its bundles in `AppKernel::registerBundles()`. If `LexxpavlovSettingsBundle`is added above your app bundles, then Settings group will be first group in menu (before your content or service groups, created in your bundles). If you want that settings group will be last group (below your groups), you add `LexxpavlovSettingsBundle` after your bundle in `AppKernel::registerBundles()`:

```
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new AppBundle\AppBundle(),
        new Lexxpavlov\SettingsBundle\LexxpavlovSettingsBundle(),
    );
}
```

### Manage settings without Sonata Admin

[](#manage-settings-without-sonata-admin)

If you don't use SonataAdminBundle in your project, you may use predefined forms or special functions.

##### Use predefined forms (in controller)

[](#use-predefined-forms-in-controller)

Save setting:

```
$form = $this->createForm('lexxpavlov_settings');
// $form->setData($setting); // use for edit of existed setting
if ($request->isMethod('POST')) {
    $form->handleRequest($request);
    if ($form->isValid()) {
        $this->get('settings')->save($form->getData());
    }
}
return array( 'form' => $form->createView() );
```

Save group:

```
$form = $this->createForm('lexxpavlov_settings_category');
if ($request->isMethod('POST')) {
    $form->handleRequest($request);
    if ($form->isValid()) {
        $this->get('settings')->saveGroup($form->getData());
    }
}
return array( 'form' => $form->createView() );
```

For use predefined forms, you need add form theme:

```
# app/config/config.yml
twig:
    # ...
    form_themes:
        - 'LexxpavlovSettingsBundle:Form:setting_value_edit.html.twig'
```

##### Manual create and update settings

[](#manual-create-and-update-settings)

```
use Lexxpavlov\SettingsBundle\DBAL\SettingsType;

// In controller:

// Get service from container
$settings = $this->get('settings');

// Update a existed setting
$settings->update('param', 'new value');
$settings->update('category', 'param_in_cat', 'new value');

// Create a new setting
$settings->create(null, 'new.1', SettingsType::Boolean, true, 'comment - setting w/o group');
$settings->create('test', 'new.2', SettingsType::Text, 'test text', 'comment - setting in group');

// Create a new empty group
$settings->createGroup('new-cat', 'comment of group');
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~145 days

Recently: every ~292 days

Total

16

Last Release

1881d ago

PHP version history (3 changes)1.0.0PHP &gt;=5.3.2

1.2.0PHP &gt;=5.4

1.5.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/e63e8dd0e183cd5e58509274cfa77520f03e230699a9b34c07123e76b73fbfaa?d=identicon)[lexxpavlov](/maintainers/lexxpavlov)

---

Top Contributors

[![lexxpavlov](https://avatars.githubusercontent.com/u/1732647?v=4)](https://github.com/lexxpavlov "lexxpavlov (26 commits)")[![PierrickMartos](https://avatars.githubusercontent.com/u/1785711?v=4)](https://github.com/PierrickMartos "PierrickMartos (9 commits)")[![dmytrof](https://avatars.githubusercontent.com/u/13831416?v=4)](https://github.com/dmytrof "dmytrof (3 commits)")[![stanislav-ivanov](https://avatars.githubusercontent.com/u/1726028?v=4)](https://github.com/stanislav-ivanov "stanislav-ivanov (1 commits)")

---

Tags

Settingssettings managementsettings bundle

### Embed Badge

![Health badge](/badges/lexxpavlov-settingsbundle/health.svg)

```
[![Health](https://phpackages.com/badges/lexxpavlov-settingsbundle/health.svg)](https://phpackages.com/packages/lexxpavlov-settingsbundle)
```

###  Alternatives

[craue/config-bundle

Database-stored settings made available via a service for your Symfony project.

1771.0M4](/packages/craue-config-bundle)[dmishh/settings-bundle

Database centric Symfony configuration management. Global and per-user settings supported.

115254.9k1](/packages/dmishh-settings-bundle)[jbtronics/settings-bundle

A symfony bundle to easily create typesafe, user-configurable settings for symfony applications

9546.7k2](/packages/jbtronics-settings-bundle)[symfony/ux-toggle-password

Toggle visibility of password inputs for Symfony Forms

26508.0k5](/packages/symfony-ux-toggle-password)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[symfony/ux-cropperjs

Cropper.js integration for Symfony

19280.3k3](/packages/symfony-ux-cropperjs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
