1

有没有办法在 ZendFramework 中定义通配符路由以将整个模块路由到另一个?

例如我想要

http://website.com/people/controller/action/路由_ _ _

http://website.com/ 朋友/控制器/动作/

我可以通过 .htaccess 做到这一点,但是除了以下 3 个句子之外,还有其他方法可以在路由中做到这一点吗?

$router->addRoute('friend',new Zend_Controller_Router_Route('people/:controller/:action',
                array("module"=>'friend')));

$router->addRoute('friend2',new Zend_Controller_Router_Route('people/:controller',
                array("module"=>'friend',"action"=>"index")));      

$router->addRoute('friend3',new Zend_Controller_Router_Route('people/',
                array("module"=>'friend',"action"=>"index","controller"=>"index")));
4

1 回答 1

2

你可以通过创建插件来做你想做的事

class My_Routing extends Zend_Controller_Plugin_Abstract
{
    public function routeShutdown($request)
    {
       $m = $this->_request->getModuleName();
       if($m == 'people') 
       {
         $this->_request->setModuleName('friends');
       }    
    }
}
于 2012-05-21T03:53:58.787 回答