简体   繁体   中英

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM