Zend Framework 2 DI alias, same controller name in different modules

I have an application with three modules and route configurations as shown below:

  • admin.domain.tld / [: controller [: / action]] => Admin
  • rest.domain.tld / [: controller [: / id]] => Rest
  • domain.tld / [: controller [: / action]] => Site

and set the DI alias for all controllers in each module

REST Module DI Alias:

'alias' => array(
    'index' => 'Rest\Controller\IndexController',
    ...
),

Admin Module Alias:

'alias' => array(
    'index' => 'Admin\Controller\IndexController',
    ...
),

DI Module Module Alias:

'alias' => array(
    'index' => 'Site\Controller\IndexController',
    ...
),

As you can see, some controllers have the same name (for example:) IndexController, but since zf2 combines configuration with LIFO behavior, the alias "index" is always from the last module added.

Application configuration

'modules' => array('Rest','Admin', 'Site'),

http://admin.domain.tld/ , index Admin\Controller\IndexController, ( ) index Site\Controller\IndexController

DI ?

+3
1

, , . , . aliasing - FQCN, .

, DI . "" [: controller [/: action]] , . .

+3

All Articles