A
A
Alexander Vladimirovich2018-08-11 11:18:32
symfony
Alexander Vladimirovich, 2018-08-11 11:18:32

How to get the value from the config inside the application?

Greetings! In the process of creating a bundle, a question arose.
There is a bundle configuration: some_package.yaml

some_package:
    test:
        value1: 11
        value2: 22

There is also some code inside the application. Let's say it's a controller.
How to get value2 in code?
PS Symfony 4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Vladimirovich, 2018-08-13
@polyanin

As a temporary solution, I did this:
SomeBundleExtension.php

public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yaml');
        $configuration = $this->getConfiguration($configs, $container);
        $config = $this->processConfiguration($configuration, $configs);
        $container->setParameter('some_bundle.config', $config);
    }

MyController.php
$config = $this->container->getParameter('some_bundle.config');
dd($config);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question