将以下行放入您的 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();
然后为每个环境创建不同的配置文件。
应用程序.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/'
)
);