2

In Zend Framework 1.8, what is the recommended way to register a new plugin in Zend Framework 1.8?

<?php
/**
 * Enter description here...
 *
 */
class Wenbert_Controller_Plugin_CheckHasAccess extends Zend_Controller_Plugin_Abstract {

    /**
     * Enter description here...
     *
     * @param Zend_Controller_Request_Abstract $request
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        echo 'This plugin is called...';
    }
}

I remember doing something like this in versions prior to 1.8:

require_once 'Wenbert/Controller/Plugin/CheckHasAccess.php';
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin(new Wenbert_Controller_Plugin_CheckHasAccess());

What would be the best / recommended way to do it in ZF 1.8?

Thanks in advance!

-Wenbert

jason
  • 8,918
  • 2
  • 37
  • 43
wenbert
  • 5,263
  • 8
  • 48
  • 77

1 Answers1

5

I'm assuming you mean the Zend_Application way of doing things. There's absolutely nothing wrong with the way you mentioned above. That said, you can specify which plugins to load in your application.ini, like so:

resources.frontController.plugins.foo = "My_Plugin_Foo"
resources.frontController.plugins.bar = "My_Plugin_Bar"

The only draw back that I am aware of with this approach, is that you cannot control the priority (location in the plugin stack) of the plugin... but for most (almost all cases) that shouldn't matter.

jason
  • 8,918
  • 2
  • 37
  • 43
  • 1
    More importantly, you can't inject objects into your plugins = increased coupling. I'd rather manually instantiate and register during bootstrapping. – Cobby Feb 08 '11 at 10:00