How do you register Zend Framework plugins in application.ini?
Currently plugins I write seem to work or not in random ways. Some do work, some don't, and some of them work part of the time, again with no obvious pattern. Even if all of the same are written and registered (apparently) in the same way. And I fail to find a proper documentation on where to put your plugins and how to register them in application.ini so I need to rely on examples I find in BLOGs or here. And chances are some of these examples assume things that may not be true in my code.
So I just give a simple example, and if you could suggest how to make it work, and give links to good articles on ZF plugins, I'd highly appreciate that...
Here's how I currently do things:
Directory structure:
/library
/Zend
/Plugins
Myplugin.php
/applications
/myApp
/configs
application.ini
/modules
/default
/controllers
/configs
/views, etc
/admin
开发者_如何学Python /controllers
/configs
/views, etc
Bootstrap.php
/public_html
index.php
Myplugin.php contains one class:
Class Plugins_Myplugin extends Zend_Controller_Plugin_Abstract
{
public function init()
{
print 'If I can see this, it's finally working!';
}
}
application.ini relevant stuff looks like this:
includePaths.library = APPLICATION_PATH "/../../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
pluginpaths.plugins = "Plugins"
resources.myplugin =
resources.frontController.plugins.myplugin = Plugins_Myplugin
;//I assume Plugins_Myplugin should be resolved into library/Plugins/Myplugin.php with class Plugins_Myplugin inside, given present configuration. Most likely I am wrong somewhere
And the most common error usually is:
Fatal error: Class 'Plugins_Myplugin' not found in /whatever/nevermind/domains/mydomain/library/Zend/Application/Resource/Frontcontroller.php on line 117
Sometimes it is found if I "register" it with just resources.myplugin =, omitting whole *resources.frontController.plugins.myplugin = Plugins_Myplugin* line.
So apparently this is not the right way to register your plugins. What is wrong with this way, and what would be the good way (using application.ini)?
you should know that your custom namespace is "Plugins" and consider adding these lines to your config :
includePaths.library = APPLICATION_PATH "/../library"
autoloaderNamespaces[] = "Plugins"
resources.frontController.plugins[] = "Plugins_Myplugin"
and make sure to delete these :
includePaths.library = APPLICATION_PATH "/../../library"
pluginpaths.plugins = "Plugins"
resources.myplugin =
resources.frontController.plugins.myplugin = Plugins_Myplugin
The method above wasn't working for me unless I changed:
autoloaderNamespaces[] = "Plugins"
to
autoloadernamespaces[] = "Plugins"
My directory structure is the Zend's default. My operating system is Windows 7 professional. I'm using WAMP... Hope it helps as I can't (or don't know how to) comment on the answer above.
The best way for u it's create some like this:
-applications
+controllers
+layouts
+models
-plugins
**Myplugin.php**
+views
In application.ini:
includePaths.plugins = APPLICATION_PATH "/plugins"
how i call this plugin.... Easy way, only need this:
public function indexAction()
{
$Myplugin = new Myplugin();
}
精彩评论