php – Zend Framework中的动态默认模块

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – Zend Framework中的动态默认模块脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有人知道在Zend Framework中动态设置认模块而不会遇到命名空间问题的方法?例如,我想要做的是有一个允许加载的模块表,其中一个模块被设置为认模块.例如,我可能有:
admin
blog
calendar

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

如果我将’calendar’更改为认模块,由于命名空间,ZF无法再找到类.

你怎么解决这个问题?我目前正在使用以下代码

$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);
如果您打算更改认模块,最好命名所有模块,然后指定认模块应该加前缀:

首先更改“博客”模块以使用命名空间:

<?PHP

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

}

然后,在Zend_Controller_Front实例上调用setParam for PRefixDefaultModule选项:

<?PHP

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

有关说明,请参阅bug # 1831.

脚本宝典总结

以上是脚本宝典为你收集整理的php – Zend Framework中的动态默认模块全部内容,希望文章能够帮你解决php – Zend Framework中的动态默认模块所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。