2011-07-05 33 views
2

的Zend路由器鏈問題我有一個子域名$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.comsite路線和programming.test.com/questions/132/test-headline匹配和question路線匹配。

但是,當我組建一個新的URL用的Zend_View的URL助手或Zend_Router對問題的途徑組裝功能,如它僅返回路徑,而不是域名:

echo $questionRoute->assemble(array('questionId' => 1, 'questionSlug' => 'testing-testing', 'siteSlug' => 'programming')); 

呼應questions/1/testing-testingprogramming.test.com/questions/1/testing-testing

我怎樣才能做到這一點?

回答

0

路由器只關心路由路徑,即採取路徑並將其匹配到您的模塊,控制器和操作。它基本上沒有意識到域。組裝只會根據您的參數創建路線(路徑)。

echo $_SERVER['HTTP_HOST'] . '/' . $questionRoute->assemble(...); 
1

試試這段代碼,對我來說工作正常(如果u需要更多的例子告訴我)

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