我在myhost.com
(reseller.myhost.com
(上添加了一个reseller
子域,并使用它来路由到我的Reseller
模块。 阅读我之前在这里发布的这个问题:点击这里
我的Reseller
路由配置如下所示:
'router' => array(
'routes' => array(
'Reseller' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'reseller.myhost.com',
'constraints' => array(
),
'defaults' => array(
'controller' => 'Reseller'Controller'Reseller',
'action' => 'index'
)
),
'may_terminate' => true,
'child_routes' => array(
'home' => array(
'type' => 'Zend'Mvc'Router'Http'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'__NAMESPACE__' => 'Reseller'Controller',
'controller' => 'Reseller',
'action' => 'index',
),
),
),
)
)
)
)
我的createdAd
路由与 reseller.myhost.com/createdAd 匹配,但我希望来自其他模块的路由不适用于此reseller
子域。
这是我的广告路由配置
'router' => array(
'routes' => array(
'locate' => array(
'type' => 'segment',
'options' => array(
'route' => '/locate[/:cityName][/:CityId][/:CategoryId][/:categoryName]',
'constraints' => array(
),
'defaults' => array(
'controller' => 'Advertise'Controller'Advertise',
'action' => 'index',
),
),
),
'createAd' => array(
'type' => 'segment',
'options' => array(
'route' => '/createAd[/:subCategoryId]',
'constraints' => array(
),
'defaults' => array(
'controller' => 'Advertise'Controller'Advertise',
'action' => 'createAd',
),
),
),
),
),
));
请注意,我想宣传没有子域的模块工作并且正常工作,只有经销商模块可以使用子域
为什么会这样?
我从您的问题中了解到:您希望createAd
路由在子域上不起作用。所以reseller.myhost.com/createdAd
不应该匹配,而是你想要一个在没有子域myhost.com/createdAd
的路由上匹配。
我建议您为 Advertise
模块创建一个单独的路由定义。
您在Advertise
模块中的路由配置 ( module/Advertise/config/module.config.php
(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Advertise'Controller'Advertise',
'action' => 'index'
)
),
)
'createAd' => array(
'type' => 'Literal',
'options' => array(
'route' => '/createAd',
'defaults' => array(
'controller' => 'Advertise'Controller'Advertise',
'action' => 'createAd',
)
)
)
)
)
您在Reseller
模块中的路由配置 ( module/Reseller/config/module.config.php
(
'router' => array(
'routes' => array(
'Reseller' => array(
'type' => 'Hostname',
'options' => array(
'route' => ':reseller.myhost.com',
),
'may_terminate' => false,
'child_routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Reseller'Controller'Reseller',
'action' => 'index'
)
)
)
)
)
)
),
您可以区分子域中的匹配项。
路由home
和createAdd
匹配没有子域的Advertise
模块。
路由reseller.home
与子域reseller.myhost.com
Reseller
模块中的索引匹配。
以及 ZF2 文档中的主机名路由示例
对于不在子域路由上的所有标准路由,您应该有一个"root"主机名。例如:
'router' => array(
'routes' => array(
'myhost' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'myhost.com',
),
),
),
),
现在,您可以将"createAd"路由(以及其他路由(添加为"myhost"路由的子路由。例如:
'router' => [
'routes' => [
'myhost' => [
'child_routes' => [
'createAd' => array(
'type' => 'segment',
'options' => array(
'route' => '/createAd[/:subCategoryId]',
'constraints' => array(
),
'defaults' => array(
'controller' => 'Advertise'Controller'Advertise',
'action' => 'createAd',
),
),
),
],
],
],
],