1
protected function _initHostnameRouter()
{
$this->bootstrap('autoload');
$this->bootstrap('FrontController');
$front = $this->getResource('FrontController');
$router = $front->getRouter();
$hostRoute1 = new Zend_Controller_Router_Route_Hostname('admin.example.net',array('module' => 'admin'));
$hostRoute2 = new Zend_Controller_Router_Route_Hostname('vouchers.example.net',array('module' => 'vouchers'));
$pathRoute = new Curo_Route_NoModule();
$router->removeDefaultRoutes();
$router->addRoute('default', $pathRoute);
$router->addRoute('admin', $hostRoute1->chain($pathRoute));
$router->addRoute('vouchers', $hostRoute2->chain($pathRoute));
}
我有上面的代码在Bootstrap文件中使用,它运行良好。我需要为管理员模块添加另一个域名。现在我使用admin.example.net
作为管理模块。我还需要添加admin.examplenew.net
。我不需要更改旧域名。两者应该同时工作。Zend_Controller_Router_Route_Hostname两个域名
我都试过了,
$hostRoute1 = new Zend_Controller_Router_Route_Hostname('admin.example.net',array('module' => 'admin'));
$hostRoute2 = new Zend_Controller_Router_Route_Hostname('vouchers.example.net',array('module' => 'vouchers'));
$hostRoute3 = new Zend_Controller_Router_Route_Hostname('admin.examplenew.net',array('module' => 'adminnew'));
$pathRoute = new Curo_Route_NoModule();
$router->removeDefaultRoutes();
$router->addRoute('default', $pathRoute);
$router->addRoute('admin', $hostRoute1->chain($pathRoute));
$router->addRoute('vouchers', $hostRoute2->chain($pathRoute));
$router->addRoute('adminnew', $hostRoute3->chain($pathRoute));
但是这两个域名并不在同一时间工作。
感谢您的回答。所以我需要为管理模块创建一个新的模块名称(比如adminnew),不是吗?我不能为不同的域引用相同的模块名称吗? – NewPHP 2013-03-11 22:39:07
无需更改模块名称;您可以将两个不同的域路由到同一个模块。上面的问题是,你正在试图添加两个不同的路由具有相同的*路由名*'admin'到路由器。如果您更改第二条路由的名称,则路由器将能够保留它们两者。 – 2013-03-12 11:30:54