我从ZF(1.9.7)开始,我想从我所有项目之间共享的库中使用View Helpers.但我找不到如何将其目录添加到帮助程序路径.当我把它们放在应用程序的助手路径中时,我的牧师会罚款.
这是错误,我找到了ZF助手的路径,以及应用程序的路径.
object(ArrayObject)#71 (3) { ["exception"]=> object(Zend_Loader_PluginLoader_Exception)#70 (6) { ["message:protected"]=> string(151) "Plugin by name 'Voo' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/;C:/ZendStd/www/applis/VOO4_PROJECTX/views\helpers/" ["string:private"]=> string(0) "" ["code:protected"]=> int(0) ["file:protected"]=> string(89) "C:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Loader\PluginLoader.php" ["line:protected"]=> int(401)
最好的问候
塞德里克
使用内置的Zend_Application资源可以非常轻松地完成视图.如果您正在使用ini配置,请添加如下所示的行:
resources.view.helperPath.My_View_Helper = "My/View/Helper"
密钥的末尾是类名前缀,以及它们所在的路径的值.
辅助路径通过Zend_View_Abstract :: addHelperPath()添加.您可以直接在现有View实例上调用此方法.
辅助路径也可以在引导期间以各种方式配置.查看ZF手册章节Zend_Application
,了解如何使用Bootstrap类和资源:
http://framework.zend.com/manual/1.12/en/zend.view.helpers.html
http://framework.zend.com/manual/1.12/en/zend.application.quick-start.html
http://framework.zend.com/manual/1.12/en/zend.application.examples.html
http://framework.zend.com/manual/1.12/en/zend.application.available-resources.html#zend.application.available-resources.view
使用时出现问题
resources.view.helperPath.App_View_Helper = APPLICATION_PATH "/../library/App/views/helpers"
我可以在布局中访问任何视图助手,甚至模块中的本地助手.(在注册表中找不到名为'LoggedInAs'的插件),但仍在视图模板文件中工作.
我把这段代码"echo Zend_Debug :: dump($ this)"放在布局文件的末尾,并且有一部分输出.
["_prefixToPaths:protected"] => array(3) { ["Zend_View_Helper_"] => array(2) { [0] => string(17) "Zend/View/Helper/" [1] => string(16) "./views\helpers/" } ["ZendX_JQuery_View_Helper_"] => array(1) { [0] => string(25) "ZendX/JQuery/View/Helper/" } ["Zend_View_Helper_Navigation_"] => array(1) { [0] => string(28) "Zend/View/Helper/Navigation/" } }
但是在bootstrap文件中使用这些代码时没有问题.
//Initialize and/or retrieve a ViewRenderer object on demand via the helper broker $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $viewRenderer->initView(); //add the global helper directory path $viewRenderer->view->addHelperPath(APPLICATION_PATH.'/../library/App/views/helpers', 'App_View_Helper');
输出如下:
["_prefixToPaths:protected"] => array(4) { ["Zend_View_Helper_"] => array(3) { [0] => string(17) "Zend/View/Helper/" [1] => string(16) "./views\helpers/" [2] => string(86) "D:/zf/application/modules/default/views\helpers/" } ["App_View_Helper_"] => array(1) { [0] => string(85) "D:\zf\application/../library/App/views/helpers/" } ["ZendX_JQuery_View_Helper_"] => array(1) { [0] => string(25) "ZendX/JQuery/View/Helper/" } ["Zend_View_Helper_Navigation_"] => array(1) { [0] => string(28) "Zend/View/Helper/Navigation/" } }