2

I would like to access to my global configs (config/{,*.}{global,local}.php) located in my personal libraries (in the vendor directory). But despite my search in the web, I did not succeed to achieve this.

I know how to access the config file of a module :

\MyModule\Module::getConfig()

I know how to access the global configurations from a controller :

$this->getServiceLocator()->get('config');

But how to access these from a file inside the vendor directory ? My libraries do not extend anything, it may be the root of the problem ? Can I use a static method to access these ?

Thanks.

Aurelien Maigret
  • 402
  • 3
  • 12
  • 2
    Can't you access the reader in the Config factory trough the Zend\\ namespace? But isn't the vendor suppose to to be seperated from Zend pattern wise? Can't you just add/overwrite the modules config? – cptnk Nov 05 '13 at 10:06
  • Hello, thank you for your comment. Indeed, you are right, I shouldn't try to use zend config files in my vendor directory. – Aurelien Maigret Nov 05 '13 at 11:11

2 Answers2

1

You can get it through the serviceManager. In controller:

$config = $this->getServiceLocator()->get('Config');

Otherwise same way, just you need service Manager, for eaxmple in Module.php:

  public function getConfig()
  {
    return include __DIR__ . '/config/module.config.php';
  }

  public function getServiceConfig()
  {
    return array(
        'factories' => array(
            'mail.transport' =>  function($sm) {
                $config = $sm->get('Config');

                 switch($config['mail']['transport']['type']){
                ..................
Zdenek Machek
  • 1,758
  • 1
  • 20
  • 30
0

easy way to do this. not only in module but anywhere.

$config = new \Zend\Config\Config( include APPLICATION_PATH.'/config/autoload/global.php' ); 

echo $config->myconfig;

define APPLICATION_PATH in public/index.php

Saurabh Chandra Patel
  • 12,712
  • 6
  • 88
  • 78