I have an application with 3 modules and route configs like below:
- admin.domain.tld/[:controller[:/action]] => Admin
- rest.domain.tld/[:controller[:/id]] => Rest
- domain.tld/[:controller[:/action]] => Site
and set DI alias for all controller in each modules
REST Module DI Alias:
'alias' => array(
'index' => 'Rest\Controller\IndexController',
...
),
Admin Module DI Alias:
'alias' => array(
'index' => 'Admin\Controller\IndexController',
...
),
Site Module DI Alias:
'alias' => array(
'index' => 'Site\Controller\IndexController',
...
),
As you see, some controllers has same name (eg: IndexController
), but since zf2 merged config with LIFO behaviour, 'index' alias always from the last added module.
Application Config
'modules' => array('Rest','Admin', 'Site'),
when i access http://admin.domain.tld/ I expect index
alias gives Admin\Controller\IndexController
but since Site Module (registered last) has same alias for index
it gives Site\Controller\IndexController
How to use different DI alias to match same controller name?
per-module solutions
until then the best solutions is using specific router for each – Komang