Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZF2 2 modules each one with router hostname

I'm trying to setup an app with 2 subdomains, each one with a hostname route and child routes but with no luck.

Any idea / example?

Thanks

like image 641
Jaume Bosch Avatar asked Oct 21 '22 17:10

Jaume Bosch


1 Answers

You can use a specific router type named "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, with "example1" in the configuration of my first module and "example2" in the configuration of my second module.

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

like image 149
Anis Avatar answered Oct 27 '22 09:10

Anis