Set current module manually

Is there a way to set the current module name manually, for example, from a controller? I do not want to define the routes for every module separately - every module has to be able to use the default "controller/action" route. So, getting the controller action to execute was simple - adding the module's controller directory to Loader does the trick. However, how can I inform the Application/Renderer/etc. to use the configuration of that particular module to render the view?

\Phalcon\Mvc\Dispatcher has the following method documented:

public setModuleName (string $moduleName) inherited from Phalcon\Dispatcher Sets the module where the controller is (only informative)

However, how could I use something like this so that it would be effective, not only informative?

Temporarily fixed by changing the view directory in module controller's initialize() method. But I'm still interested in what would be the proper solution.

The standard definition of "module" in application architecture implies that you want to separate different components of an application into different areas or folders. For instance, you want to have a main site, a blog and a store, you will end up with something like:,, This can be done with modules, in witch you will have separated controllers, models and views for each. But you have to define where the modules are and which module you want to use to process the request by configuring application routes.

When Phalcon analyses the incoming request, it will match the request with the routes to determine witch module you want to access. So you really have to define different routes to each module so that the application can use the right controller for the content you want.

For more reading about multi modules and routes, look here:

It's exactly what I'm doing - the modules are separate components that reside in their own directories. Basically what I'm trying to achieve is auto-detecting which module was executed. I'm adding all the module controller directories to Loader in the bootstrap part and Phalcon would execute the controller action. The only problem was actually changing the view directory as well, which I have resolved by extending Volt.