Download the PHP package c975l/config-bundle without Composer
On this page you can find all versions of the php package c975l/config-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download c975l/config-bundle
More information about c975l/config-bundle
Files in c975l/config-bundle
Package config-bundle
Short Description Used to get/set the config params for a Symfony app
License MIT
Homepage https://github.com/975L/ConfigBundle
Informations about the package config-bundle
ConfigBundle
Please not that this Bundle >= v2.0 doesn't use the Configuration
class to build the modify form for parameters, but its own defined system of key-value. See branch 1.x for the use case with Configuration
class.
ConfigBundle does the following:
- Gets the config parameters definition from a yaml file for a Symfony app,
- Build a form to allow end-user to modify these parameters (acces-rights are checked on your side),
- Provides a Twig extension to get these parameters values in a Twig template,
ConfigBundle dedicated web page.
ConfigBundle API documentation.
Bundle installation
Step 1: Download the Bundle
Use Composer to install the library
Step 2: Enable the Bundles
Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php
file of your project:
Step 3: Override templates
It is strongly recommended to use the Override Templates from Third-Party Bundles feature to integrate fully with your site.
For this, simply, create the following structure templates/bundles/c975LConfigBundle/views/
in your app and then duplicate the file layout.html.twig
in it, to override the existing Bundle file.
In layout.html.twig
, it will mainly consist to extend your layout and define specific variables, i.e. :
How to use
In your Bundle, you need to create a file /config/bundle.yaml
(description of the needed fields) + Controller (Route to access config form) + Voter (Checking for access rights) and that's it! Code examples are given below.
Before the first use, if parameters are requested you must use the console command php bin/console config:create
to create the config files from default data of the bundle.
When updating the configuration, two files are created:
config/config_bundles.yaml
that contains the values for defined fields, You must add this file to your.gitignore
to ensure not storing data, like API keys, to a public/private repositorycache/dev|prod|test/configBundles.php
that contains an associative array of the fields'yourRoot.yourParameter' => 'value'
.
Then your Controller file:
Then call the defined Route in a web browser and set-up (or your user) the configuration parameters.
Get parameter inside a class
To get a parameter inside a class, use the following code:
Check if parameter is defined inside a class
To check if a parameter has been defined, use $configService->hasParameter('yourRoot.yourParameter')
.
Get Container's paramaters
You can use $configService->getContainerParameter('parameter')
to access container's parameters and avoid injecting Container
when ConfigService
is already injected.
Twig Extensions
If you need to access a parameter inside a Twig template, simply use {{ config('yourRoot.yourParameter') }}
.
If you need to access a container's parameter inside a Twig template, simply use {{ configParam('parameter') }}
.
If this project help you to reduce time to develop, you can sponsor me via the "Sponsor" button at the top :)
All versions of config-bundle with dependencies
c975l/includelibrary-bundle Version *
c975l/services-bundle Version *
c975l/toolbar-bundle Version *
symfony/form Version *
symfony/yaml Version *