I am trying to use same route names for the 2 different modules, is it possible?
Module User :
/*Module.config.php*/
'dashboard' => array(
'type' => 'segment',
'options' => array(
'route' => '/dashboard',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Users\Controller\Users',
'action' => 'dashboard',
),
),
),
Module Admin :
/*Module.config.php*/
'dashboard' => array(
'type' => 'segment',
'options' => array(
'route' => '/dashboard',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Admin\Controller\Admin',
'action' => 'dashboard',
),
),
),
Eventhough I am creating 2 different modules for the dashboard, I am loading only any one action.
How can I achieve this ?
I think you can not have the same name for two different routes. Yes it's two different modules, but it's the same application.
The reason is that when the Zend\ModuleManager loads the modules, the event
ModuleEvent::EVENT_LOAD_MODULEwill be triggered and then the listenerZend\ModuleManager\Listener\ConfigListenerwill call the functiongetConfig()of each single Module in your application. And then, all theModule->getConfig()will be merged into one internal configuration calledapplication.config.This is to say that when the modules are loaded, you'll have two routes with th same name, and the difference between the modules doesn't affect nothing in the routing.
Even if could do that, you'll encounter other problems as when you want to use Redirect Plugin, for example the
toRoutemethod need the route name as parameter :This is a problem if you have to call it with the same route name.
A possible solution for your problem is to set one route and add the module to it, as follows :
/dashboard/admin/the-rest-of-the-url
/dashboard/user/the-rest-of-the-url
You'll have something like this in your route configuration :