Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
             /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)?

like image 683
Sejanus Avatar asked Dec 21 '22 16:12

Sejanus


1 Answers

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
like image 117
tawfekov Avatar answered Mar 16 '23 12:03

tawfekov