I have an application with 3 modules and route configs like below:
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?
Before the new view layer was merged into master, it was required to have aliases for controllers to behave correctly when resolving view scripts. Now this is not required anymore, it is even not recommended anymore to use aliases for controllers. The problem with aliasing is there is one alias for one FQCN, so your problem is directly related to this.
What you need to do is to remove aliases from the DI configuration and use explicit routes instead. The "magic" route [:controller[/:action]] is a bad practice and results in more problems than it can help you. So write some explicit routes and remove the aliases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With