2013-05-04 59 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/' 
    ) 
);