Zend Router 子域链接问题

发布于 2024-11-18 07:33:33 字数 1237 浏览 4 评论 0原文

我有一个用于子域的 $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一紙繁鸢 2024-11-25 07:33:33

尝试这段代码,对我来说效果很好(如果你需要更多示例告诉我)

$router = Zend_Controller_Front::getInstance()->getRouter();
echo $router->assemble(array('questionId' => 1, 'questionSlug' => 'testing-testing', 'siteSlug' => 'programming'), 'question');

Try this piece of code, works fine for me (if u need more example tell me)

$router = Zend_Controller_Front::getInstance()->getRouter();
echo $router->assemble(array('questionId' => 1, 'questionSlug' => 'testing-testing', 'siteSlug' => 'programming'), 'question');
强辩 2024-11-25 07:33:33

路由器只关心路由路径,即获取路径并将其与您的模块、控制器和操作相匹配。它基本上没有域意识。 Assemble 仅根据您的参数创建路线(路径)。

echo $_SERVER['HTTP_HOST'] . '/' . $questionRoute->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.

echo $_SERVER['HTTP_HOST'] . '/' . $questionRoute->assemble(...);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文