ZF2按主机名路由与其他模块一起使用 [英] ZF2 Routing by Hostname works with other modules
问题描述
我在 myhost.com
( reseller.myhost。)上添加了
),然后将其用于路由到我的转销商
子域。 com Reseller
模块。请阅读我之前在此发布的问题:单击此处
I added a reseller
subdomain on my myhost.com
(reseller.myhost.com
) and I use it for routing to my Reseller
module. Read this question I posted before here: click here
我的经销商
路由配置如下:
'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匹配但我希望其他模块的路由在此经销商
子域上不起作用。
My createdAd
route matches on reseller.myhost.com/createdAd but I expect routes from other modules not work on this reseller
subdomain.
这是我的广告路由配置
'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',
),
),
),
),
),
));
请注意,我要播发不带子域的模块,并正常工作,只有转售商模块和子域一起工作
be notice that i want to advertise module work without subdomain and work normally and only reseller module work with subdomain
为什么会这样?
推荐答案
您应该有一个根主机名,而不是在子域路由上的所有标准路由。例如:
You should have a "root" hostname for all your standard routes not on the subdomain route. Eg:
'router' => array(
'routes' => array(
'myhost' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'myhost.com',
),
),
),
),
现在,您可以将 createAd路由(和其他路由)添加为 myhost路由的子路由。例如:
Now you can add your 'createAd' route (and other routes) as a child route of the 'myhost' route. Eg:
'router' => [
'routes' => [
'myhost' => [
'child_routes' => [
'createAd' => array(
'type' => 'segment',
'options' => array(
'route' => '/createAd[/:subCategoryId]',
'constraints' => array(
),
'defaults' => array(
'controller' => 'Advertise\Controller\Advertise',
'action' => 'createAd',
),
),
),
],
],
],
],
这篇关于ZF2按主机名路由与其他模块一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!