视图脚本无法识别 zend 框架中的视图助手

发布于 2024-11-16 02:26:32 字数 799 浏览 1 评论 0原文

我的问题是,当我从视图脚本调用视图助手时,它无法被调用 虽然我通过这一行正确添加了配置文件的所有信息路径:

resources.view.helperPath.ZF_View_Helper_="ZF/View/Helper/"

我还在引导文件中注册了帮助程序

function _initViewHelpers(){
    $view = new Zend_View();    
    $view->addHelperPath('ZF/View/Helper','ZF_View_Helper');
    $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
    $viewRenderer->setView($view);
    Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
}

,但徒劳地它仍然打印出此错误消息:

Application error
Exception information:
Message: Plugin by name 'OutputHelper' was not found in the registry; used paths: 
Zend_View_Helper_: Zend/View/Helper/  

它不包括预期的自定义视图帮助程序路径;

视图助手的路径是:library/ZF/View/Helper/OutputHelper.php

my problem is fairly when I call a view helper from view script it can't be called
although I added properly all information path to the config file via this line:

resources.view.helperPath.ZF_View_Helper_="ZF/View/Helper/"

also I registered the helper in bootstrap file

function _initViewHelpers(){
    $view = new Zend_View();    
    $view->addHelperPath('ZF/View/Helper','ZF_View_Helper');
    $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
    $viewRenderer->setView($view);
    Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
}

but in vain it still printing out this error message:

Application error
Exception information:
Message: Plugin by name 'OutputHelper' was not found in the registry; used paths: 
Zend_View_Helper_: Zend/View/Helper/  

it doesn't include the custom view helper path as expected ;

the path of the view helper is: library/ZF/View/Helper/OutputHelper.php

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦忆晨望 2024-11-23 02:26:32

你能这样做吗:

在视图脚本中,

$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
var_dump($this === $view);
var_dump($view->getHelperPaths());
exit;

我认为你的视图实例在某个时刻被替换。
模块的引导程序可能有查看资源吗?

或者也可能是其他明显的错误。如此明显,所以您永远不会想到

删除 _initViewHelpers 方法。 Zend_Application_Resource_View 工作得很好。
如果您使用此方法,请正确使用它,例如:

$this->bootstrap('view');
$view = $this->getResource('view');
//whatever

can you do this:

in view script

$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
var_dump($this === $view);
var_dump($view->getHelperPaths());
exit;

I think your view instance are replaced at some point.
May be module's bootstrap have view resource?

Or it can be other obvious mistake. So obvious so you'll never think of it

btw remove that _initViewHelpers method. Zend_Application_Resource_View work just fine for that.
And if you use this method, use it correctly, eg:

$this->bootstrap('view');
$view = $this->getResource('view');
//whatever
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文