在 Zend 框架中更改模块名称 [英] Change Module Name in Zend Framework

查看:31
本文介绍了在 Zend 框架中更改模块名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

采埃孚 1.9.6尝试根据请求的用户代理更改模块.当我尝试从 Front 获取请求对象时,我得到 NULL.

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.

目前我正在尝试通过我创建的 Bootstrap _initModule 方法设置模块名称.

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.

推荐答案

我不认为 Bootstrap 是正确的地方,因为它发生在任何请求路由开始之前.

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

我建议为此使用 preDispatch 前端控制器插件:

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');
    }
...
}

与:

resources.frontController.plugins.moduleselector = "Your_Application_Plugin_ModuleSelector"

在你application.ini

这篇关于在 Zend 框架中更改模块名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆