Access to module config in Zend Framework 2

前端 未结 8 2114
清酒与你
清酒与你 2021-01-30 21:05

How I can get access to my module config from the controller?

8条回答
  •  一整个雨季
    2021-01-30 21:41

    for Beta5, you can add function like this in Module.php

    public function init(ModuleManager $moduleManager)
    { 
        $sharedEvents = $moduleManager->getEventManager()->getSharedManager();
        $sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
              $config = $e->getApplication()->getConfiguration();
              $controller = $e->getTarget();
              $controller->config = $config;
        });
     }
    

    in controller, you can get config :

    print_r($this->config); 
    

提交回复
热议问题