Of controller plugins and directory layout
By Geoffrey on Sunday 23 September 2007, 00:55 - Coding - Permalink
When anyone on #zftalk ask about where controller plugins should be kept, we usually responds something like have your own library namesapce alongside Zend/ and put it in it like YourNamespace/Controller/Plugin/YourPlugin.php. But what about application specific controllers ? There's a time where you have to write a plugin that relies on the application at such a level that using it elsewhere would make no sense. In that case, where can we store this plugin ? The question arised this morning, and we ended up to the fact that having a controller-level plugin directory would not hurt, after all. So one could have the following directory layout (simplified on purpose):
/application/modules/default
/controllers
/library/Plugin
MyPlugin.php
The drawback is that in order to use autoload you would have to have each modules Plugin dir in the include path, which is a bit of a hassle. Instead, we could have the much more simple folloing layout:
/application
library/Controller/Plugin
MyPlugin.php
Which is simpler but does not allow for modules specific plugins. Anyway, the former layout would require a bit more logic in the bootstrap in order to extract every modules path as plugins are registered pre-dispatch.
Hope it helps with directory layout organization :-)
UPDATE
What I've finally decided to do is the following:
/application
library/App/Controller/Plugin
MyPlugin.php
So that application specific code gets prefixed with the App_ namespace.