2010-11-29 105 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

另請檢查子域是否是合法變量名。嘗試將其更改爲子域。

相關問題