开发者

Zend Router chaining problem with subdomain

I have a $siteRoute for subdomains:

$siteRoute = new Zend_Controller_Router_Route_Hostname(
    ':siteSlug.test.com',
    array(
        'module' => 'site',
    ),
    array('siteSlug' => '^(programming|photography|gaming)$')            
);
$router->addRoute('site', $siteRoute);

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 开发者_StackOverflowthis?


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');


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(...);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜