views:

164

answers:

2

Hi all,

The question is quite simple : I have a controller plugin for Zend Framework.

Should I put it in the "library/Plugin" folder, or in "application/plugins".

(btw for now it is in library/Plugin but this works on Linux and Mac Os X, but not Windows so i figured maybe that is not the right place)

Thank you

+2  A: 

I generally put everything that is specific to my application, e.g. not reusable without modification into the appropriate application folder.

For generic plugins, I create a new folder in library. This folder is modeled after the Zend library folder concerning names, e.g. My/Controller/Action/Helper or My/Controller/Plugin, etc. Putting stuff there is optional though, as you might as well put this in the appropriate application folder as well. I just like the distinction.

I never put anything into the standard Zend distribution. This would get lost when updating.

Gordon
If I put it in My/Controller/Plugin, will the autoloader figure the include path correctly ? How should I name my controller then ?
Matthieu
@Matthieu By convention, the autoloader will change underscores in a class name to slashes to find files on the include path, so if the classname was My_Controller_Plugin_Something, the loader would try to load My/Controller/Plugin/Something.php. However, in case of plugins you might also have to configure the plugin broker. See http://framework.zend.com/manual/en/zend.controller.plugins.html and http://framework.zend.com/manual/1.10/en/zend.loader.pluginloader.html
Gordon
@Matthieu Actually, you are bit vague as to what you mean by plugins. I'm only assuming you are talking about controller plugins. But I am not sure you are not refering to view or action helpers
Gordon
yes I am referering to controller plugins, and I was thinking of simply naming my plugin : My_Plugin_AclBut I can add "Controller_" before "Plugin", though i'd rather avoid that (stupid reason, it's shorter, I can live without it)
Matthieu
@Matthieu, before PHP5.3 these long names made up for namespaces. I know they can be tedious to write but they have a purpose. They are also part of the Zend Code Convention which I strongly encourage you to follow: http://framework.zend.com/manual/en/coding-standard.html
Gordon
Actually I had an error on Windows (not mac nor unix) : it was looking for plugins (ie classes starting with "My_Plugin") in the folder application/pluginsWhen I put the class in this folder, everything works automatically. I think it's a predefined folder like "controllers" and "views" that Zend Framework uses by default.The problem is : I want a class name My_Plugin..._Abstract in my library (used by many project)and ZF raises include errors (but still works) arghhh
Matthieu
@Matthieu like I said and linked in the comments, placing it in lib is optional. You can configure where ZF looks for plugins. If you just want to use the defaults, put them in application. If not, configure ZF accordingly.
Gordon
+1  A: 

If its a controller plugin it goes in "application/plugins".
If it's a general purpose plugin (ie Utility Classes and such) it goes in /library/*, where * follows the Zend Loader rules.

clyfe
But if my controller name is My_Plugin_Blah, will autoload find it in the folder "application/plugins/Blah.php" (no problem for the module name "My" though, it is properly configured)
Matthieu
Ok I answer myself, autoload actually finds it in application/plugins
Matthieu