ZF2 2 modules each with the hostname of the router

I am trying to configure an application with two subdomains, each with a hostname route and child routes, but no luck.

Any idea / example?

thank

+5
source share
1 answer

You can use a specific type of router with the name "Hostname" (class "Zend \ Mvc \ Router \ Http \ Hostname"). Here is a simple example:

'router' => array(
    'routes' => array(
        'example1' => array(
            'type' => 'Hostname',
            'options' => array(
                'route' => ':subdomain.mydomain.com',
                'constraints' => array(
                    'subdomain' => 'mysubdomain1',
                ),
                'defaults' => array(
                    'controller' => 'MyModule1\Controller\MyFirstController',
                    'action' => 'index',
                ),
            ),
        ),
        'example2' => array(
            'type' => 'Hostname',
            'options' => array(
                'route' => ':subdomain.mydomain.com',
                'constraints' => array(
                    'subdomain' => 'mysubdomain2',
                ),
                'defaults' => array(
                    'controller' => 'MyModule2\Controller\MySecondController',
                    'action' => 'index',
                ),
            ),
        ),
    ),
),

I would probably split this configuration into two parts: "example1" in the configuration of my first module and "example2" in the configuration of my second module.

You will find complete information about this type of router and others on this page .

+3
source

All Articles