开发者

Module-specific Controller plugins in Zend Framework

My Zend Framework project is divided into certain Mod开发者_如何转开发ules. 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

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. There are a few neat ideas floating around: Kathryn's Active module config

Jeroen's Moduleconfig

Matthijs' ModuleConfig

Pádraic and Rob's Module Configurators proposal

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜