Robert Basic's blog

Loading custom module plugins

by Robert Basic on July 20th, 2010

OK, here's a quicky one from the office :P

I was trying to load a Front Controller plugin which resides in app/modules/my_module/controllers/plugins/ and not in the "usual" lib/My_App/Plugin/. I want this plugin to be called in every request and I want the plugin file to be under it's "parent" module.

Here's what I did: added the path to the plugin and it's namespace to the Zend_Application_Module_Autoloader as a new resource type and then just register the plugin in the front controller in an other _init method.

Code is better, here's some:

class News_Bootstrap extends Zend_Application_Module_Bootstrap
     * Autoloader for the "news" module
     * @return Zend_Application_Module_Autoloader
    public function _initNewsAutoload()
        $moduleLoader = new Zend_Application_Module_Autoloader(
                                    'namespace' => 'News',
                                    'basePath' => APPLICATION_PATH . '/modules/news'

        // adding model resources to the autoloader
                    'plugins' => array(
                        'path' => 'controllers/plugins',
                        'namespace' => 'Controller_Plugin'

        return $moduleLoader;

    public function _initPlugins()
        $fc = $this->getResource('frontcontroller');

        $fc->registerPlugin(new News_Controller_Plugin_Scheduler());

If anyone knows a better way for doing this, please do share it with me.

Now back to work. Cheerio.

Tags: framework, loading, php, plugin, zend.
Categories: Development, Programming.