Loading custom module plugins

published on July 20, 2010.
Heads-up! You're reading an old post and the information in it is quite probably outdated.

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.

Thanks for reading! If you require help on a project of any kind, let's talk!

Robert Basic

Robert Basic

Software engineer, consultant, open source contributor.

Let's work together!

If you require outsourcing or consulting help on your projects, I'm available!

Robert Basic © 2008 — 2018
Get the feed