2010-11-29 102 views
6

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

我在我的引导下面的代码得到“未指定的子域。”

$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。 如果我将默认值设置为主机名路由,我不会收到错误,但布局中的网址使用默认值而不是当前主机名中的值。

谁能帮我解决这个问题?

回答

1

您应该为子域定义默认值。更改$ defaultRoute为此:

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

它应该工作。

+1

这与他写的或我是盲目的没有什么不同? – 2011-07-15 10:49:57

1

您在生成URL时遇到了问题。你应该为你的主机名像这样指定路由定义变量参数:子域:

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

否则Zend的网址助手不能为你的定义 生成URL。域名:TLD。提供示例将生成此网址: your-subdomain-here.your-domain.com/current_controller/current_action

另请检查子域是否是合法变量名。尝试将其更改为子域。

相关问题