MikeGA
MikeGA

Reputation: 1262

Zend Framework Plugins Location & Name

I have been trying to create my own plugins and so far nothing seems to work for me, let's assume I am going to have my plugins directory under the application folder, which I think is the default location:

 application/plugins/WhosOnline.php

The contents of my plugin:

Class My_Plugin_WhosOnline extends Zend_Controller_Plugin_Abstract

{
     public function preDispatch(Zend_Controller_Request_Abstract $request) {

       echo 'I have reached the plugin';
           exit;

     }
}

How exactly do I register this plugin in the application.ini file? I have tried:

 resources.frontController.plugins.whosonline = "My_Plugin_WhosOnline"

I have also tried:

 resources.frontController.plugins[] = "My_Plugin_WhosOnline"

I get the error:

 Class 'My_Plugin_WhosOnline' not found

How can I match those paths?? Do I have to create the directory application/plugins/My/Plugin/ and then put the WhosOnline.php file there? Do I have to register the namespace My_Plugin? If so, how do I do that? Please help! I know this question has been asked before but I need someone to explain it to me much slower.

Upvotes: 2

Views: 151

Answers (3)

MikeGA
MikeGA

Reputation: 1262

After playing a lot with it I ended up doing the following, I added these to my application.ini:

autoloaderNamespaces[] = "MyPlugins_"
resources.frontController.plugins.WhosOnline = "MyPlugins_WhosOnline"

Then I created a folder called MyPlugins inside the library folder and then I created my plugin file, called WhosOnline.php with the contents:

    Class MyPlugins_WhosOnline extends Zend_Controller_Plugin_Abstract 
    { 
        public function preDispatch(Zend_Controller_Request_Abstract $request) {

            echo 'I have reached the plugin';
            exit;

        }   
    }

I finally got it working!

Upvotes: 0

drew010
drew010

Reputation: 69957

If the plugin is located in application/plugins/WhosOnline.php, then the default class name for a Zend Application would be Application_Plugin_WhosOnline.

If your appnamespace is something other than Application, then that would be the prefix for your class.

If you want the class to be called My_Plugin_WhosOnline, create a folder called My in the library folder with a subfolder called Plugin (not plugins), and put the file there and add Zend_Loader_Autoloader::getInstance()->registerNamespace('My_'); to your Bootstrap.

Upvotes: 2

satrun77
satrun77

Reputation: 3220

What you have is correct just add the following in your application.ini

appnamespace = "My"

Upvotes: 1

Related Questions