1

OK, here's the problem:

I have a module in my Zend Framework 2 application that I wish to not include on production. Therefore, I made a file inside config/autoload called local.php with the following content:

'modules' => array(
    'Application',
    'My_Local_Module',
),

while config/application.config.php contains:

'modules' => array(
    'Application',
),

When I try to access the module in the URL, a 404 is returned. However, when I set the modules inside the application.config.php file, the module is displayed properly. The environment variable is set to local.

2 Answers 2

1

Put the following lines in your index.php:

<?php

// ...

// Get the current environment (development, testing, staging, production, ...)
$env = strtolower(getenv('APPLICATION_ENV'));

// Assume production if environment not defined
if (empty($env)) {
    $env = 'production';
}

// Get the default config file
$config = require 'config/application.config.php';

// Check if the environment config file exists and merge it with the default
$env_config_file = 'config/application.' . $env . '.config.php';
if (is_readable($env_config_file)) {
    $config = array_merge_recursive($config, require $env_config_file);
}

// Run the application!
Zend\Mvc\Application::init($config)->run();

Then create different configuration files for each environment.

application.config.php:

<?php

return array(
    'modules' => array(
        'Application'
    ),
    'module_listener_options' => array(
        'config_glob_paths' => array(
            'config/autoload/{,*.}{global,local}.php'
        ),
        'module_paths' => array(
            './module',
            './vendor'
        )
    )
);

application.development.config.php:

<?php

return array(
    'modules' => array(
        'ZendDeveloperTools'
    )
);

application.production.config.php:

<?php

return array(
    'module_listener_options' => array(
        'config_cache_enabled' => true,
        'module_map_cache_enabled' => true,
        'cache_dir' => 'data/cache/'
    )
);
Sign up to request clarification or add additional context in comments.

Comments

0

You have to enumerate all your modules inside application.config.php, so the config should look like that:

$modules = array (
    'Application'
);

if (IS_LOCAL_DOMAIN)
{
    $modules [] = "My_Local_Module";
}

return array(
    'modules' => $modules,
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            'config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' => array(
            './module',
            './vendor',
        ),
    ),
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.