我正在尝试创建一项服务,帮助用户从系统管理面板中加载模块。那是我的代码:
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()
);
}
我认为这不是以模块方式加载模块的最佳做法。
答案 0 :(得分:0)
试试这个
$configuration = $serviceManager->get('ApplicationConfig');
$configuration['modules'][] = 'ModuleName';
$serviceManager->setService('ApplicationConfig', $configuration);
$serviceManager->get('ModuleManager')->loadModules();