我期待转发我的所有请求:
.com/m/
至
.com/
我想我可以尝试在模块的引导程序中执行此操作,但尚未设置前端控制器。我不断看到提到前端控制器插件,但我将如何为这个模块设置它?
抱歉这些愚蠢的问题,我仍在努力掌握 Zend 框架。
我期待转发我的所有请求:
.com/m/
至
.com/
我想我可以尝试在模块的引导程序中执行此操作,但尚未设置前端控制器。我不断看到提到前端控制器插件,但我将如何为这个模块设置它?
抱歉这些愚蠢的问题,我仍在努力掌握 Zend 框架。
Here is a controller plugin that routes all traffic to a specific module to the default module. I give 2 ways to route the traffic, either by forwarding the request (url stays the same but executes default module), or by then redirecting the browser to the default module.
Note, this is untested but should work. Let me know if you have questions or problems with it.
<?php
class Application_Plugin_ModuleRedirector extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
// don't execute plugin if not in the module "m"
if ($module != 'm') {
return ;
}
// foward to default module with same controller and action
$request->setModuleName('default')
->setControllerName($controller)
->setActionName($action);
// OR remove the above and use this for a hard redirect
$urlHelper = new Zend_View_Helper_Url();
$url = $urlHelper->url(array(
'module' => 'default',
'controller' => $controller,
'action' => $action));
$redirector = Zend_Controller_Action_HelperBroker::
getStaticHelper('redirector');
$redirector->gotoUrl($url);
}
}
To activate it, register the plugin with the Front Controller:
Zend_Controller_Front::getInstance()->registerPlugin(new Application_Plugin_ModuleRedirector());