[英]Zend Framework - How do to preDispatch for all controllers?
我无法加载此插件,如何加载此插件?
我有IndexController.php,还有OthersController.php。 对于所有这些控制器,要有1个单独的preDispatch方法,我编写了一个插件,如下所示。 能否请您友好地指导我,我现在如何将其与所有其他控制器连接在一起???
@file:application / controllers / GlobalControllerPlugin.php
class GlobalControllerPlugin extends Zend_Controller_Plugin_Abstract { public function preDispatch() { $this->view->helloworld = '(from preDispatch)--->(controllers)--->(views)--->yesGreat)'; } }
您必须将插件添加(注册)到前端控制器。
在Bootstrap.php
,
public function _initGlobalPlugin() {
$this->bootstrap('frontController');
// require_once 'GlobalControllerPlugin.php';
$plugin = new GlobalControllerPlugin();
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin($plugin);
return $plugin;
}
或在application.ini
:
resources.frontController.plugins.global = "Global_Controller_Plugin_Common"
确保已正确配置自动加载器以加载您使用的名称空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.