I am trying to load modules on the basis of user type in addition to Application module i.e. Application modules is always loaded since it is mentioned in application.config.php
file if user is of type 1 I want to load module A, B and D and if user is of type 2, I want to load module C, E and F.
in Module.php
of Application module's onBootstrap
function I load modules dynamically, and when I see the result var_dump($moduleManager->loadedModules())
, it shows the array of the correct modules that are loaded
But the issue that I am facing is that even though modules are loaded correctly their configuration is not loaded.
Example:
In my module A I have a service called, SomethingService
and it is being used in indexAction
of IndexController
in Application
module. But it throws the exception which states
Unable to fetch or create instance of SomethingService
After some debugging I found that even though the modules are loaded their configuration from module.config.php
is not loaded and is not availble in Config
service.
To overcome this issue, where I load module, I now get the config using $module->getConfig()
method merge if with the Config service and override Config service using the following code
$this->serviceLocator->setAllowOverride(true);
$this->serviceLocator->setService('config', $mergedConfig);
$this->serviceLocator->setAllowOverride(false);
As a result of this , when I get config using $this->serviceLocator->get('config);
I see that all the modules config is merged and is available in the config array.
After doing all of this, I am still getting the exception that I mentioned above. Maybe I am doing all of this at the wrong location?