Change Module Name in Zend Framework

心已入冬 提交于 2019-12-22 10:00:07

问题


ZF 1.9.6 Trying to change the module based on the user agent of the request. When I try to get the request object from the Front, I get NULL.

Currently I'm trying to set the module name from the Bootstrap _initModule method I created.

$front = Zend_Controller_Front::getInstance();
$request = $front->getRequest(); // This is NULL
$request = new Zend_Controller_Request_Http();
$request->setModuleName('iphone');
$front->setRequest($request);

However, when executed, it's still going to the 'default' module.


回答1:


I don't think Bootstrap is the right place, because it happens before any request routing starts.

I'd suggest using preDispatch front controller plugin for that:

class Your_Application_Plugin_ModuleSelector extends Zend_Controller_Plugin_Abstract {
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        ...
        $request->setModuleName('iphone');
    }
...
}

With:

resources.frontController.plugins.moduleselector = "Your_Application_Plugin_ModuleSelector"

in you application.ini



来源:https://stackoverflow.com/questions/1885109/change-module-name-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!