6

我需要基于 zend_framework 运行同一个站点以在多个域上运行,并且我的应用程序需要知道它在哪个域上运行。我认为使用 Zend_Controller_Router_Route_Hostname 是个好主意,但我遇到了一些问题。

我的引导程序中有以下代码

$ctrl = Zend_Controller_Front::getInstance();
$router = $ctrl->getRouter();
$router->removeDefaultRoutes();     

$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
    ':sub-domain.:domain.:tld'
);

$defaultRoute = new Zend_Controller_Router_Route(
    ':controller/:action/*',
    array(
        'controller' => 'index',
        'action' => 'index'
    )
);
$router->addRoute('default',$hostnameRoute->chain($defaultRoute));

我收到以下错误“未指定子域”。我想我追踪到我的布局文件中的 $this->url 在路由与请求 url 匹配之前使用定义的路由来组装 url。如果我将默认值设置为主机名路由,我不会收到错误消息,但布局中的 url 使用默认值而不是当前主机名中的值。

谁能帮我解决这个问题?

4

2 回答 2

1

您在生成 URL 时遇到了问题。您应该为主机名的路由定义中的变量指定参数,如下所示:

echo $this->url(array('sub-domain' => 'your-subdomain-here', 'domain' => 'your-domain', 'tld' => 'com'), 'default');

否则 Zend URL 助手无法为您的定义生成 url :sub-domain.:domain.:tld 。提供的示例将生成此 url:your-subdomain-here.your-domain.com/current_controller/current_action

还要检查子域是否是合法的变量名。尝试将其更改为子域。

于 2012-03-01T17:41:34.440 回答
1

您应该为子域定义一个默认值。将$ 更改为defaultRoute

$defaultRoute = new Zend_Controller_Router_Route(
    ':controller/:action/*',
    array(
        'controller' => 'index',
        'action' => 'index'
    )
);

它应该工作。

于 2011-07-02T19:30:52.020 回答