Zend框架中的动态默认模块 [英] Dynamic Default Module in Zend Framework

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

问题描述

有人知道在Zend Framework中动态设置默认模块而不遇到名称空间问题的方法吗?例如,我要做的是有一个允许加载的模块表,其中一个设置为默认模块.例如,我可能有:

Does anyone know of a way to set the default module dynamically in Zend Framework and not run into namespace issues? For example, what I want to do is have a table of modules that are allowed to be loaded, with one of them set as the default module. For example, I may have:

admin
blog
calendar

作为可以加载的模块.如果我将'blog'作为默认模块,则'admin'和'calendar'必须将其控制器命名为(Admin_IndexController,Calendar_IndexController),而'blog'则不是(IndexController).

as modules that can be loaded. If I have 'blog' as the default module, then 'admin' and 'calendar' have to have their controllers namespaced (Admin_IndexController, Calendar_IndexController) while 'blog' isn't (IndexController).

如果我将"calendar"更改为默认模块,则ZF会由于命名空间的原因而不再找到这些类.

If I change 'calendar' to be the default module, ZF can no longer find the classes because of the namespacing.

您如何解决?我目前正在使用以下代码:

How do you get around that? I'm currently using the following code:

$modules = new Modules();
$activeModules = $modules->fetchActive();
foreach($activeModules as $mod) {
    $loadedModules[$mod->name] = '..application/modules/' . $mod->name . '/controllers';
    if($mod->default) {
        $defaultModule = $mod->name;
    }
}
$frontController->setControllerDirectory($loadedModules);
$frontController->setDefaultModule($defaultModule);

推荐答案

如果计划更改默认模块,则最好对 ALL 模块命名,然后指定默认模块加上前缀:

If you plan on changing the default module, it is probably best to namespace ALL modules, and then specify that the default module should be prefixed:

首先将博客"模块更改为使用命名空间:

First change the "blog" module to use namespacing:

<?php

// Used to be "class IndexController"
class Blog_IndexController extends Zend_Controller_Action {

}

然后,在Zend_Controller_Front实例上为 prefixDefaultModule 选项调用 setParam :

Then, call setParam for prefixDefaultModule option on your instance of Zend_Controller_Front:

<?php

    // Allow your default module to be prefixed
    $frontController->setParam('prefixDefaultModule', true);

有关说明,请参见错误#1831 .

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

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