Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Symfony 4 | Load custom configuration block from YAML file

$
0
0

It's me again, Hi.

Today I need to load a custom block from a configuration file located in a custom bundle, I have the following code in my bundle:

class ExampleAdminExtension extends Extension {

    /**
     * Loads a specific configuration.
     *
     * @throws \InvalidArgumentException When provided tag is not defined in this extension
     */
    public function load(array $configs, ContainerBuilder $container) {
        $loader = new YamlFileLoader( $container, new FileLocator(__DIR__.'/../Resources/config') );
        $loader->load('custom.yaml');
    }
}

Then the custom.yaml:

parameters:
  allowTraps: 
    - 'Eeeeh?'
    - 'Easy modo??'
    - 'How lame!'

This does works, having everything inside parameters I can go to a random controller and then print its records with:

$trapsAllowed = $this->getParameter('allowTraps');
dump($trapsAllowed);

The question here is, when I add a custom block outside parameters like this:

parameters:
  allowTraps: 
    - 'Eeeeh?'
    - 'Easy modo??'
    - 'How lame!'

items:
  - 'Maruchan'
  - 'How to turn off my chainsaw??'
  - 'Heelppplp'

it throws an error that says:

There is no extension able to load the configuration for "items". Looked for namespace "items", found none

I wish to know how can I achieve this, have a custom configuration block a load it successfully like when I put it inside the parameters block.

Thank you for reading me.


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>