2013-04-15 147 views
1

我正在使用Zend,这里是我的问题,我有两个不同的网址,我真的想保持它们的样子。将Zend_Router路由到特定模块

我希望URL:“www.urlA.com”被定向到application/moduleA/indexController/indexAction 和“www.urlB.com”到application/index/index。

换句话说,我希望Zend_Router确保当我输入www.urlA.com/index/login我使用应用程序/ 模块A /索引控制器和loginAction()。

我想保留经典的Zend路由,只是添加了我的模块已经在url中指定的事实。

我有以下代码INT引导:

protected function _initRouter() 
{ 
    $router = Zend_Controller_Front::getInstance()->getRouter(); 
    $route = new Zend_Controller_Router_Route_Hostname(
     'www.urlA.com', 
     array(
      'module'=>'moduleA' 
     ) 
    ); 
    $routeURI = new Zend_Controller_Router_Route(); 
    $router->addRoute('modulea', $route->chain($routeURI)); 
} 

这样的“乌拉”我正确地去moduleA /索引/索引,但
“乌拉/指数/登录”不起作用。

感谢您的任何帮助。

回答

1

我也有类似的问题,曾经和我写了这个:

//ADMIN page 
$admin = array('module' => 'admin', 'controller' => 'index', 'action' => 'index'); 
$hostRoute_admin = new Zend_Controller_Router_Route_Hostname('admin.mysite.com', $admin); 

//special environement Website 
$env = array('module' => 'env', 'controller' => 'index', 'action' => 'index'); 
$hostRoute_env = new Zend_Controller_Router_Route_Hostname('env.mysite.com', $env); 

//Zend classic routing 
$plainPathRoute = new Zend_Controller_Router_Route(':controller/:action/*', 
     array('controller' => 'index', 'action' => 'index')); 

//add specific routing 
Zend_Controller_Front::getInstance()->getRouter()->addRoute('admin', $hostRoute_admin->chain($plainPathRoute)); 
Zend_Controller_Front::getInstance()->getRouter()->addRoute('env', $hostRoute_env->chain($plainPathRoute));