Search code examples
phpmodulezend-framework2servicemanager

how to retrieve values of ModuleName.global.php config files in autoload directory in Zend 2?


I've been looking for information on this question but the only answer I can find is by looking at how other modules take care of this. So far, I have seen this:

With CdliTwoStageSignup in Module.php

   'factories' => array(
                    .
                    .
            'cdlitwostagesignup_module_options' => function($sm) {
                $config = $sm->get('Configuration');
                return new Options\ModuleOptions($config['cdli-twostagesignup']);
            },
                    .
     }

With ZfcUser in Module.php

        'factories' => array(

            'zfcuser_module_options' => function ($sm) {
                $config = $sm->get('Config');
                return new Options\ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array());
            },

Based on Zend 2 documentation, ModuleManager Merges all the module.config.php of each module and is set in the service manager. Also, config files in .config/autoload directory can override the module config files.

To access the configurations, these two modules seem to use the keywords: "Config" and "Configuration".

  • Are these always the the keywords used with the service manager to get to config files?
  • Is there any difference between choosing one over the other?

Appreciate any answer you can provide.


Solution

  • The keywork used should be config. Internally, afaik, all key, aliases, etc.. will be turned from CamelCase to dash-separated-lowercase. So Config equals config as far as configuration is concerned.

    Now when it comes down to configuration vs. config i assume configuration was left available as an alias to config. At one point, i think beta 4 or beta 5 they've decided that all occurences of configuration will be replaced by the well known abbreviated form of config. If ever there is any occurence of configuration that not acts as a fallback to config all community will appreciate you opening an issue on github to get it fixed.