Access to module config in Zend Framework 2

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

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

8条回答
  •  清酒与你
    2021-01-30 21:38

    I created the module with controller plugin and view helper for reading a config in controllers and views. GitHub link __ Composer link

    Install it via composer

    composer require tasmaniski/zf2-config-helper
    

    Register new module "ConfigHelper" in your config/application.config.php file

    'modules' => array(
        '...',
        'ConfigHelper'
    ),
    

    Use it in controller and view files

    echo $this->configHelp('key_from_config'); // read specific key from config 
    
    $config = $this->configHelp(); // return config object Zend\Config\Config
    echo $config->key_from_config;
    

提交回复
热议问题