Frage

I have a Zend front controller plugin. It depends on the request object, and on the service layer, but it is not reusable across applications. Therefore, I think it belongs in a Plugins directory within the application's controller directory. Does this sound right?

Secondly, how can I get Zend to autoload the plugins in this directory?

Thanks!

War es hilfreich?

Lösung

I would agree that plugins should go in the plugins folder. I normally setup an instance of the resource autoloader during bootstrap using my app's custom namespace. E.g. say your app's namespace was 'Bob':

protected function _initAutoloader()
{
    $autoloader = Zend_Loader_Autoloader::getInstance();

    $resourceAutoloader = new Zend_Loader_Autoloader_Resource(array(
        'basePath' => APPLICATION_PATH,
        'namespace' => 'Bob',
        'resourceTypes' => array(
            'model' => array(
                'path' => 'models/',
                'namespace' => 'Model'
            ),
            'form' => array(
                'path' => 'forms/',
                'namespace' => 'Form'
            ),
            'plugin' => array(
                'path' => 'plugins/',
                'namespace' => 'Plugin'
            ),
            'service' => array(
                'path' => 'services/',
                'namespace' => 'Service'
            )
        )
    ));
    $autoloader->pushAutoloader($resourceAutoloader);

    return $autoloader;
}

Add or remove resource types as required. You can then put your plugin in application/plugins/Whatever.php and it will be autoloaded as normal.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top