Zend Router 子域链接问题
我有一个用于子域的 $siteRoute
:
$siteRoute = new Zend_Controller_Router_Route_Hostname(
':siteSlug.test.com',
array(
'module' => 'site',
),
array('siteSlug' => '^(programming|photography|gaming)$')
);
$router->addRoute('site', $siteRoute);
我有一个用于问题的 $questionRoute ,
$questionRoute = new Zend_Controller_Router_Route(
'questions/:questionId/:questionSlug',
array(
'controller' => 'question',
'action' => 'view',
'questionSlug' => ''
)
);
$router->addRoute('question', $siteRoute->chain($questionRoute));
所有这两个路由都匹配,没有任何问题。例如: programming.test.com
匹配并调度 site
路由,programming.test.com/questions/132/test-headline
匹配 >问题
路线。
但是,当我使用 Zend_View 的 url 帮助程序或 Zend_Router 的问题路由组装函数组装新的 url 时,它仅返回路径,而不是域,例如:
echo $questionRoute->assemble(array('questionId' => 1, 'questionSlug' => 'testing-testing', 'siteSlug' => 'programming'));
echoes questions/1/testing-testing
not programming。 test.com/questions/1/testing-testing
。
我该怎么做?
I have a $siteRoute
for subdomains:
$siteRoute = new Zend_Controller_Router_Route_Hostname(
':siteSlug.test.com',
array(
'module' => 'site',
),
array('siteSlug' => '^(programming|photography|gaming)
and i have $questionRoute for questions' fancy
$questionRoute = new Zend_Controller_Router_Route(
'questions/:questionId/:questionSlug',
array(
'controller' => 'question',
'action' => 'view',
'questionSlug' => ''
)
);
$router->addRoute('question', $siteRoute->chain($questionRoute));
all these two routes are matching without any problems. for example:
programming.test.com
matches and dispatches for site
route and programming.test.com/questions/132/test-headline
matches for question
route.
But when i assemble a new url with Zend_View's url helper or Zend_Router's assemble function for question route, it returns just the path, not domain like:
echo $questionRoute->assemble(array('questionId' => 1, 'questionSlug' => 'testing-testing', 'siteSlug' => 'programming'));
echoes questions/1/testing-testing
not programming.test.com/questions/1/testing-testing
.
How can i do this?
)
);
$router->addRoute('site', $siteRoute);
and i have $questionRoute for questions' fancy
all these two routes are matching without any problems. for example:programming.test.com
matches and dispatches for site
route and programming.test.com/questions/132/test-headline
matches for question
route.
But when i assemble a new url with Zend_View's url helper or Zend_Router's assemble function for question route, it returns just the path, not domain like:
echoes questions/1/testing-testing
not programming.test.com/questions/1/testing-testing
.
How can i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这段代码,对我来说效果很好(如果你需要更多示例告诉我)
Try this piece of code, works fine for me (if u need more example tell me)
路由器只关心路由路径,即获取路径并将其与您的模块、控制器和操作相匹配。它基本上没有域意识。 Assemble 仅根据您的参数创建路线(路径)。
The router is only concerned about routing the path, i.e. take the path and match it to your modules, controllers and actions. It has basically no awareness of the domain. Assemble only creates the route (path) based on your arguments.