2

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 this?

cnkt
  • 2,943
  • 5
  • 30
  • 43

2 Answers2

1

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');
Vitor Almeida
  • 81
  • 1
  • 8
0

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(...);
Adrian World
  • 3,118
  • 2
  • 16
  • 25