我在reseller
(myhost.com
)上添加了reseller.myhost.com
子域名,我用它来路由到我的Reseller
模块。请阅读我之前发布的这个问题:click here
我的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',
),
),
),
),
),
));
请注意,我想宣传没有子域的模块工作并正常工作,只有经销商模块才能使用子域
为什么会这样?
答案 0 :(得分:0)
我从您的问题中了解到:您希望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
内reseller.myhost.com
模块中的索引匹配。
还要检查主机名路由示例here in the ZF2 documentation
的详细信息答案 1 :(得分:0)
你应该有一个" root"不在子域路由上的所有标准路由的主机名。例如:
'router' => array(
'routes' => array(
'myhost' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'myhost.com',
),
),
),
),
现在您可以添加' createAd'路线(和其他路线)作为“我的主人”的儿童路线。路线。例如:
'router' => [
'routes' => [
'myhost' => [
'child_routes' => [
'createAd' => array(
'type' => 'segment',
'options' => array(
'route' => '/createAd[/:subCategoryId]',
'constraints' => array(
),
'defaults' => array(
'controller' => 'Advertise\Controller\Advertise',
'action' => 'createAd',
),
),
),
],
],
],
],