How to connect the plugin to the front controller?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/code-flow.club/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
3 views
Want to put in the plug-in access rights, but are faced with the problem of creating a plugin. Tried to look for a solution in the official manual and in other articles, but there are examples of the plugin code and connection code, which says you need to write to Bootstrap. But the problem is that I simply did not know where to put written file, what would the Zend have seen it, and when you add in the Bootstrap code from the example get error.
PS project structure standard created by zend_tool.
by | 3 views

2 Answers

0 like 0 dislike
Plugins for FrontController'a connect like this:
\r
$front = Zend_Controller_Front::getInstance(); $front->registerPlugin(new You_Plugin_Example()); 

It is clear that before the instantiation is necessary to connect a file with the plugin class:
\r
require APPLICATION_PATH . '/path/to/plugins/example.php'; 

But it is better to configure the autoloader. This can be done in several ways:
\r
    \r
  1. You can download the plugin from your own library. To do this, connect the new namespace:
    \r
    $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('You_'); 

    \r
  2. \r
  3. You can specify the boot loader prefix and the directory with the plugins:
    \r
    $loader = new Zend_Loader_PluginLoader(); $loader->addPrefixPath('You_Plugin', APPLICATION_PATH . '/path/to/plugins/'); 

    \r
  4. \r
  5. You can add the necessary directories in the module autoloader:
    \r
    $module = new Zend_Application_Module_Autoloader(array( 'namespace' => 'Example', 'basePath' => APPLICATION_PATH . '/modules/example', 'resourceTypes' => array( 'plugin' => array( 'namespace' => 'Plugin', 'path' => 'plugins/', ), ) )); 

    \r
  6. \r
by
0 like 0 dislike
In application\\Bootstrap.php add a method _initControllerPlugins(). If the plugins do not need parameters, it is possible in the application.ini to add the line resources.frontController.plugins
\r
Here's an example:
protected function _initControllerPlugins()
{
$acl = new AclModel();
$auth = Zend_Auth::getInstance();
\r
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin(new My_Controller_Plugin_Acl($acl, $auth));
$frontController->registerPlugin(new My_Controller_Plugin_AuthCookie($auth));
}
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
22,998 users