Zend Framework: How to register and call plugin in bootstrap file

3.3k Views Asked by At

1- How can I register and call my plugin in bootstrap file?

2- Is it a better way to use boostrap file intead of application.ini file for registering and calling my plugins ?

Note: Iam using custom path ('Mylib/Controller/Plugin') for storing my plugins.

Actually I want to convert following 'application.ini' entries

autoloaderNamespaces[] = "Mylib_"
resources.frontController.plugins.CheckHasAccess = "Mylib_Controller_Plugin_CheckHasAccess"

into bootstrap _initPlugin function.

Can some one guide me in this regards with some sample code.

Thanks in advance

1

There are 1 best solutions below

0
On BEST ANSWER

1 - You would need first to load your plugin class (via Zend_Loader or require_once) then create your plugin yourself:

$plugin = new MyPlugin();

then you can call any public method of your plugin you want and at the end you can register it within front controller:

Zend_Controller_Front::getInstance()->registerPlugin($plugin);

2 - if your plugins need to be somehow configured before they can be used by framework - then you can create and configure them yourself (as described above). If they don't need any special actions - then you can let them to be created by Framework automatically.