我正在使用Zend Framework开发一个模块化应用程序,我发现我使用了许多在我的所有模块中都通用的视图助手,我希望使用以下结构,其中我有一个在任何模块中使用的视图助手的中心位置,每个模块都有自己的视图助手。这可能吗?
APPLICATION_PATH
/modules/module1/views/helpers
/modules/module2/views/helpers
/modules/module3/views/helpers
/views/helpers <-- central location for all modules
感谢Joelord的帮助,根据Joelord提供的信息,我能够从中心位置加载视图帮助程序,以及位于我的每个模块中的视图帮助程序。我在我的主应用程序引导文件中添加了以下内容:
public function _initView(){
$view = new Zend_View($this->getOptions());
$view->setEncoding('UTF-8');
$view->addHelperPath(APPLICATION_PATH.'/helpers/', 'Application_Helpers_');
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer'
);
$viewRenderer->setView($view);
return $view;
}
在我的引导程序中,我有以下功能:
protected function _initView() {
$view->addHelperPath(APPLICATION_PATH."/../library/Myapp/View/Helper/", 'Myapp_View_Helper_');
}
这有助于我实现我认为你想要的。我的普通助手都位于/library/Myapp/View/Helper