转载zendframework 插件方式

Zend Framework中,我们经常会根据自己的要求自定义一些插件,一般有三种办法来进行加载:

1.添加到index.php文件中
定义前端控制器,注册一个插件

1 $frontController = Zend_Controller_front::getInstance();
2 $frontController->registerPlugin(new MyApp_Controller_Plugin_Smarty);

如:Zend Framework整合Smarty

2.直接添加在配置文件application/configs/application.ini中

1 resources.frontController.plugins.smarty = "App_Controller_Plugin_Smarty"

3.当自定义的插件有参数时,没办法直接写在配置文件中加载,我们可以用第一种方法,这里还介绍一个在Bootstrap.php中加载的方法:

1 protected function _initAutoloade(){
2 $auth = Zend_Auth::getInstance();
3 $acl new App_LwAcl();
4 Zend_Controller_Front::getInstance()->registerPlugin(new App_Controller_Plugin_LwAuth($auth$acl));
5 }
原文地址:https://www.cnblogs.com/phplover/p/3026917.html