How do you register Zend Framework plugins in application.ini?

Currently, the plugins I write seem to work or not randomly. Some of them work, some do not, and some of them work part time, again without an obvious picture. Even if they are all written and registered (apparently) the same way. And I cannot find the correct documentation on where to place your plugins and how to register them in application.ini, so I need to rely on the examples that I find on blogs or here. Probably some of these examples suggest things that might be wrong in my code.

So, I will just give a simple example, and if you could suggest how to make it work, and provide links to good articles about ZF plugins, I would really appreciate that ...

This is how I am doing it now:

Directory structure:

/library /Zend /Plugins Myplugin.php /applications /myApp /configs application.ini /modules /default /controllers /configs /views, etc /admin /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 finally working!'; } } 

The relevant application.ini material is as follows:

 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 mistake is usually this:

Fatal error: class 'Plugins_Myplugin' not found in /whatever/nevermind/domains/mydomain/library/Zend/Application/Resource/Frontcontroller.php on line 117

Sometimes this can be found if I "register" it only with the resources .myplugin =, omitting the whole * resources.frontController.plugins.myplugin = Plugins_Myplugin *.

So, apparently, this is the wrong way to register your plugins. What is wrong with this, and what would be a good way (using application.ini)?

+4
source share
3 answers

you should know that your own namespace is β€œPlugins” and consider adding these lines to your configuration:

 includePaths.library = APPLICATION_PATH "/../library" autoloaderNamespaces[] = "Plugins" resources.frontController.plugins[] = "Plugins_Myplugin" 

and be sure to delete them:

 includePaths.library = APPLICATION_PATH "/../../library" pluginpaths.plugins = "Plugins" resources.myplugin = resources.frontController.plugins.myplugin = Plugins_Myplugin 
+11
source

The method above did not work for me unless I changed:

 autoloaderNamespaces[] = "Plugins" 

to

 autoloaderNamespaces[] = "Plugins" 

My directory structure is the default value for Zend. My operating system is Windows 7 professional. I use WAMP ... Hope this helps, as I cannot (or don't know how) to comment on the answer above.

0
source

The best way for u to create some of these:

 -applications +controllers +layouts +models -plugins **Myplugin.php** +views 

In application.ini:

 includePaths.plugins = APPLICATION_PATH "/plugins" 

as I call this plugin .... A simple way, just need to:

 public function indexAction() { $Myplugin = new Myplugin(); } 
0
source

Source: https://habr.com/ru/post/1345885/


All Articles