views:

58

answers:

1

Hi,

My Zend Framework project is divided into certain Modules. 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?

+1  A: 

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

tawfekov
Yep, but... Quite frankly, that is exactly what I _don't_ want - testing the Module Name in each and every Plugin.
RWS
@your Edit: I did miss this at first, but read it just some moments ago. Okay, seems like I have to wait for Zend Framework to live up to the expectations I had when I read about their module concept...
RWS