Modular controller plugins in Zend Framework

My Zend Framework project is divided into specific modules. Each module has specific controller plugins.

Now the problem is that all plugins are loaded and registered (and therefore called) - regardless of which module the user is trying to access.

I could check which module we are in and stop executing directly in the plugins, but I would have to do this in each plugin ...

Is there an elegant way to register only module-specific plugins? Or am I trying to solve the wrong problem here?

+4
source share
1 answer

This is an example of module specific modules.

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, other ways are listed in the same article above:

Is there a better way to do this?

Yes, there are probably more efficient ways to do this. The true problem is that the modules are currently second-class citizens in ZF. There are a few neat ideas floating around: Kathryn Active module configuration

Jeroen moduleconfig

Matthijs ModuleConfig

Design proposal for Pรกdraic and Rob modules

+6
source

All Articles