ZF2最佳实践,用于加载模块

时间:2016-06-03 15:05:26

标签: zend-framework zend-framework2

我正在尝试创建一项服务,帮助用户从系统管理面板中加载模块。那是我的代码:

if(!$this->isModuleInstalled($moduleName)) {
      $appConfigService = $this->getServiceManager()->get('ApplicationConfig');
      $appConfig = new Config($appConfigService, true);

      $modules = $config->modules->toArray();
      end($modules);
      $nextModuleKey = (key($modules) + 1);
      unset($modules);

      $config->modules->{$nextModuleKey} = $moduleName;

      $writter = new Writer\PhpArray();
      $writter->toFile(
            __DIR__ . '/../../../../../config/application.config.php', 
            $config->toArray()
      );
}

我认为这不是以模块方式加载模块的最佳做法。

1 个答案:

答案 0 :(得分:0)

试试这个

$configuration = $serviceManager->get('ApplicationConfig');
$configuration['modules'][] = 'ModuleName';
$serviceManager->setService('ApplicationConfig', $configuration);
$serviceManager->get('ModuleManager')->loadModules();