2
votes

This may be a silly question, but i can't see how to access this data :

In the main app/config/config.yml, i have the general configuration data for my application.

parameters:    #accessible by getParameter()
    locale: fr
    # ...
fos_user:    #accessible by ???
    #...
    registration:
        form:
            from_email:
                address:     [email protected]
                sender_name: TheSenderName

In my custom bundle i can access the parameters from that config.yml file with :

$this->container->getParameter('locale'); //gives me "fr" as expected

But how can i access the non parameters configuration values ?

i would like here to get the adress defined in te FOS User bundle configuration : I can't do

$admin_adress = $this->container->getParameter('fos_user.registration.confirmation.from_email.address');

What is the right way to access thoses ?

Edit : Yes i wanted to access this config data from FOS User Bundle (here in the example, but it could be any), inside a controller or whatever in my bundle.

3
Are you requiring this for a Bundle you have made?Adam Harrison
Yep. Silly question. Well, not really. Only parameters can be directly accessed via getParameter. Normal configuration stuff will not be available unless the bundle itself makes them available. Your best bet would be to define from_email as a parameter. Or maybe dig into the bundle and see if they are exposed somewhere.Cerad
couldn't he set them as parameters using the bundle configuration and extension class ?Adam Harrison
Thank you for all your comments and solutions. I see now that it wasn't such a naive question. I nailvely thought that since every bundle have their configuration in config.yml, there was a "regular" way (a SF function) too access any of those in my custom bundle (in a controller, listener, manager or whatever). To me, Don Calisto solution is the easiest one. It's better than duplicating the parameters elsewhere. But still, in the example (FOS User bundle), this is a standard config data value.Overdose
I created a bundle for accessing final configuration values of each registered bundle (built-in like the SecurityBundle included). See github.com/chalasr/RCHConfigAccessBundlechalasr

3 Answers

0
votes

You can act that way

parameters:
    locale: fr
    fos_user:
        registration:
            form:
                from_email:
                    address: [email protected]
    # ...
fos_user:
    #...
    registration:
        form:
            from_email:
                address:     %fos_user.registration.form.from_email.address%
                sender_name: TheSenderName

Of course I've choose this name just to fit your controller request for parameter: you can (and maybe should) choose other keys.

However with container->getParameter you can access only parameters section of your configuration file (plus parameters exposed from vendors)

2
votes

I think this question nailed it

class MyProjectExtension extends Extension
{
    public function load( array $configs, ContainerBuilder $container )
    {
        // The next 2 lines are pretty common to all Extension templates.
        $configuration = new Configuration();
        $processedConfig = $this->processConfiguration( $configuration, $configs );

        // This is the KEY TO YOUR ANSWER
        $container->setParameter( 'from_email.address', $processedConfig[ 'registration.confirmation.from_email.address' ];

        // Other stuff like loading services.yml
    }
0
votes

One of the solutions can be passing your controller as a service, then inject your parameters like that :

# services.yml
my.amazing.controller:
    class: CompanyFirst\LabBundle\Controller\PloufController
    arguments:
        - '@filesystem'
        - '%dump_file_convention%' // your config parameter