简体   繁体   English

Zend Framework中特定于模块的Controller插件

[英]Module-specific Controller plugins in Zend Framework

My Zend Framework project is divided into certain Modules. 我的Zend Framework项目分为几个模块。 Each Module has some specific Controller Plugins. 每个模块都有一些特定的控制器插件。

Now, the problem is that all plugins get loaded and registered (and thus, called) - no matter which module the user is trying to access. 现在,问题是所有插件都被加载和注册(因此被调用) - 无论用户尝试访问哪个模块。

I could test in which module we are and stop execution directly in the plugins, but I would have to do this in each and every plugin... 可以测试我们在哪个模块中并直接在插件中停止执行,但我必须在每个插件中执行此操作...

Is there an elegant way to register only module-specific plugins? 是否有一种优雅的方式来只注册特定于模块的插件? Or am I trying to solve the wrong problem here? 或者我在这里试图解决错误的问题?

This is an example of Module specific Plugins 这是模块特定插件的示例

Taken from http://weierophinney.net/matthew/archives/234-Module-Bootstraps-in-Zend-Framework-Dos-and-Donts.html 摘自http://weierophinney.net/matthew/archives/234-Module-Bootstraps-in-Zend-Framework-Dos-and-Donts.html

class Foomodule_Plugin_Layout extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        if ('foomodule' != $request->getModuleName()) {
            // If not in this module, return early
            return;
        }

        // Change layout
        Zend_Layout::getMvcInstance()->setLayout('foomodule');
    }
}

UPDATE: in case you missed , there other ways listed in the same article above : 更新:万一你错过了,上面同一篇文章中列出了其他方式:

Isn't there a better way to do this? 有没有更好的方法来做到这一点?

Yes, likely there are better ways to accomplish this. 是的,可能有更好的方法来实现这一目标。 The true problem is that modules are really second-class citizens in ZF currently. 真正的问题是模块目前在ZF中确实是二等公民。 There are a few neat ideas floating around: Kathryn's Active module config 有一些巧妙的想法浮出水面: Kathryn的Active模块配置

Jeroen's Moduleconfig Jeroen的Moduleconfig

Matthijs' ModuleConfig Matthijs的ModuleConfig

Pádraic and Rob's Module Configurators proposal Pádraic和Rob的模块配置器提案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM