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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.