2013-05-04 34 views
0

OK,這裏的問題:Zend框架2:在生產環境中禁用模塊

我有一個模塊在我的Zend Framework 2應用程序,我想不包括生產。因此,我做了內config/autoload一個名爲local.php,內容如下:

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

config/application.config.php包含:

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

當我嘗試訪問模塊中的URL,一個404返回。但是,當我在application.config.php文件內設置modules時,模塊顯示正常。環境變量設置爲local

回答

0

您必須枚舉裏面application.config.php你的所有模塊,所以配置應該是這樣的:

$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', 
     ), 
    ), 
); 
1

把下面的行中的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/' 
    ) 
);