Search code examples
zend-frameworkzend-framework3

Set APPLICATION_ENV in Zend framework 3


I've enabled development mode using composer development-enable . How can I check in my module's config/module.config.php that development is enabled or not?

I've also added SetEnv APPLICATION_ENV development in public/.htaccess and tried to use it in module.config.php using echo APPLICATION_ENV;exit; but it doesn't give me environment.

How I can set and get application environment in zend framework 3?


Solution

  • use the correct function ;)

    $environment = getenv('APPLICATION_ENV');
    

    Usage for config in ZF2/3:

    $env = getenv('APPLICATION_ENV'); // Expect null or "development"
    
    $modules = [];
    
    if ($env === 'development') {
        //Array of modules used only for development
        $modules = array_merge_recursive($modules, [
            'Zf2Whoops',
        ]);
    }
    

    In just Zend Framework nothing special happens with the usage of composer development-enable. However, if you use Apigility at some point, it will create a development.config.php file for you which disables application caches.