把下面的行中的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();
然後爲每個環境創建不同的配置文件。
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/'
)
);