Where to put custom settings in Zend Framework 2?

前端 未结 4 1492
有刺的猬
有刺的猬 2021-02-04 10:47

I have some custom application specific settings, I want to put in a configuration file. Where would I put these? I considered /config/autoload/global.php and/or local.php. But

4条回答
  •  一个人的身影
    2021-02-04 11:23

    You can use any option from the following.

    Option 1

    Create one file called config/autoload/custom.global.php. In custom.global.php

    return array(
        'settings' => array(
            'settingA' => 'foo',
            'settingB' => 'bar'
        )
    )
    

    And in controller,

    $config = $this->getServiceLocator()->get('Config');
    echo $config['settings']['settingA'];
    

    Option 2

    In config\autoload\global.php or config\autoload\local.php

    return array(
        // Predefined settings if any
        'customsetting' => array(
            'settings' => array(
                'settingA' => 'foo',
                'settingB' => 'bar'
             )
        )
    )
    

    And in controller,

    $config = $this->getServiceLocator()->get('Config');
    echo $config['customsetting']['settings']['settingA'];
    

    Option 3

    In module.config.php

    return array(
        'settings' => array(
            'settingA' => 'foo',
            'settingB' => 'bar'
        )
    )
    

    And in controller,

    $config = $this->getServiceLocator()->get('Config');
    echo $config['settings']['settingA'];
    

提交回复
热议问题