views:

216

answers:

3

Let's say I have the following in my ini file:

resources.frontController.plugins.auth = AuthPlugin

Where should the AuthPlugin class be placed? Let's say I would like it under controllers/plugins.

UPDATE:

Based on the suggestions below I am still having trouble. Let me be exact in what I currently have:

1) main part of application.ini

includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] =
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.plugins.authplugin.class = "AuthPlugin"

2) my Bootstrap.php has nothing (I had lots of things in there, but still get the error with nothing):

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
}

3) I have an AuthPlugin.php class in application/plugins directory

class AuthPlugin extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
        { 
           // code here
        }
}

I get the following error:

Fatal error: Class 'AuthPlugin' not found in C:\[my dir structure here]\Application\Resource\Frontcontroller.php on line 111

I assume I'm missing something obvious here. Thanks in advance. Zend Framework 1.10

A: 

I think in /application/plugins/

But you could also set another Directory for it.

streetparade
Thanks, but that doesn't seem to work. It may be that my autoloading isn't working right for this type of class, but it can't find my AuthPlugin class whether I put it under application/plugins or controllers.
Arthur Frankel
did you also bootstrapped the plugin by registrering it?
streetparade
resources.frontController.pluginDirectory = APPLICATION_PATH"/plugins"
streetparade
place that in your ini file
streetparade
I don't have it bootstrapped (I thought it only needed to be in the ini file). The .pluginDirectory setting doesn't seem to help (also I thought I read somewhere that this ini setting was proposed and not implemented yet).
Arthur Frankel
A: 

Since the application will bootstrap itself from the config file after registering the Autoloader, you should put AuthPlugin.php (which should contain the AuthPlugin class) in the include path.

racetrack
I tried this but I can't get it working. I updated the description with lots more information. Maybe you can spot what I'm missing.
Arthur Frankel
A: 

This is how I register a plugin named Foo_Plugin_SuperDuperPlugin in my application config:

resources.frontController.plugins.superduperplugin.class = "Foo_Plugin_SuperDuperPlugin"

The plugin is located at
APPLICATION_PATH/plugins/Foo_Plugin_SuperDuperPlugin.php and is autoloaded from there because the Resource Module Autoloader automatically looks in that (recommended) location for plugin type resources. If I wanted to load the plugin from, say,
APPLICATION_PATH/controllers/plugins/Foo_Plugin_SuperDuperPlugin.php then I would register a new resource loader with the autoloader and define a type of resource named 'plugin' and the path to those plugin resources. So in my bootstrap.php

protected function _initAutoloader()
{
    $autoloader = new Zend_Loader_Autoloader_Resource(
        array(
            'basePath'      => APPLICATION_PATH,
            'namespace'     => 'Foo',
            'resourceTypes' => array(
                'plugin' => array(
                    'path'      => 'controllers/plugins',
                    'namespace' => 'Plugin',
                )
            )
        )
    );
}

and then I need to ensure that this method is bootstrapped before the SuperDuperPlugin is registered (which, in this example, happens when the application config is read resources.frontcontroller.plugins.superduperplugin.class = ...). This can be achieved by placing the _initAutoloader method at the top of the bootstrap.php or by calling $this->bootstrap('autoLoader'); from any other _init method, before the frontController resource is initialised.

UPDATED: Try adding this to your bootstrap:

protected function _initAutoloader()
{
    $autoloader = new Zend_Loader_Autoloader_Resource(
        array(
            'basePath'      => APPLICATION_PATH,
            'resourceTypes' => array(
                'plugin' => array(
                    'path'      => 'controllers/plugins',
                    'namespace' => '',
                )
            )
        )
    );
}

and maybe even leave off the namespace. Or: add appnamespace = "Foo" to your config and rename the class to Foo_Plugin_AuthPlugin.

jah
I must be doing something wrong then, because I can't get this to work. I am updating the original question with more details.
Arthur Frankel
I've updated my answer.
jah
I could get it working with the resource addition, but I finally did get it working with a basic require 'controllers/AuthPlugin.php'; (or whatever dir I put it in) into the _initAutoloader() method.
Arthur Frankel
I meant couldn't above (in terms of using Zend_Loader_Autoloader_Resource) but could using a basic require.
Arthur Frankel
Well there's nothing wrong with using a require directive. Still, it seems to me that yours is a naming issue - the class should certainly be named differently if you want it to be loaded from APPLICATION_PATH/plugins - it should be named Plugin_AuthPlugin and it might also need another prefix (ZF examples usually go for 'My_' and I was using 'Foo_' in my examples), but that depends on what prefix (or 'namespace') your autoloaders are configured to hunt for.
jah
I finally got this working. There's actually an issue I believe in the documentation that someone else pointed out. You must use a namespace - whereas I was trying not to use one. Thank you.
Arthur Frankel