我在视图中访问自定义视图助手时遇到了一个问题。在布局中调用helper。
ZF Version: 1.11.2
application.ini
resources.view[] =
引导:protected function _initViewSettings()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
$view->setScriptPath(APPLICATION_PATH . '/views/scripts/');
$view->addHelperPath(APPLICATION_PATH . '/layouts/helpers/', 'Layout_Helper_');
$view->addHelperPath(APPLICATION_PATH . '/views/helpers/', 'View_Helper_');
}
助手:(应用程序/视图/帮助/Loader.php)
class View_Helper_Loader extends Zend_View_Helper_Abstract
{
public function loader()
{
$loader_html = '
<div class="loading">
<div class="bullet"></div>
<div class="bullet"></div>
<div class="bullet"></div>
<div class="bullet"></div>
</div>';
return $loader_html;
}
}
视图:
<?php
echo $this->loader();
?>
错误:Plugin by name 'Loader' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/
为什么我不能在视图中使用helper ?
也许可以尝试显式地将视图添加到视图渲染器中:
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer'
);
$viewRenderer->setView($view);
我不能完全重现你的问题——让它在布局中工作,但在视图中不起作用。
如果我在application.ini中添加一个视图资源,ZF 1.11.14中的一些连接会自动为我发生,但是如果我在bootstrap中创建视图(new Zend_View)作为资源,我必须显式地将其传递给视图渲染器。
修复。
问题是在我的操作中的以下行:
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
我认为我的助手的结果无论如何都会被解析到我的视图中。糟糕的错误。