ZF2 2模块每个都带有路由器主机名

Jau*_*sch 5 php zend-framework2

我正在尝试设置一个带有2个子域的应用程序,每个子域都有一个主机名路由和子路由,但没有运气.

任何想法/例子?

谢谢

Ani*_*nis 3

您可以使用名为“Hostname”的特定路由器类型(类“Zend\Mvc\Router\Http\Hostname”)。这是一个简单的例子:

'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',
                ),
            ),
        ),
    ),
),
Run Code Online (Sandbox Code Playgroud)

我可能会将此配置分成两部分,其中“example1”在我的第一个模块的配置中,“example2”在我的第二个模块的配置中。

您可以在此页面上找到有关该路由器类型和其他类型的完整信息。