Zend Framework - 从 View 访问 View Helper

Zend Framework - Access to View Helper from View

我在访问视图中的自定义视图助手时遇到问题。在 layout.phtml 中调用帮助程序非常有效。

ZF版本:1.11.2

application.ini

resources.view[] =

Bootstrap:

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_');

}

帮手:(application/views/helpers/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/

为什么我不能在我的视图中使用助手?

也许尝试将您的视图显式添加到视图渲染器:

    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
        'ViewRenderer'
    );
    $viewRenderer->setView($view);

我无法完全重现您的问题 - 让它在布局中起作用,但在视图中不起作用。

如果我将视图资源添加到 application.ini,在 ZF 1.11.14 中一些连接会自动发生,但如果我在 Zend_View 中创建视图(新 Zend_View) =19=] 作为资源,我必须将它显式传递给视图渲染器。

已修复。

问题出在我的操作中的以下几行:

    $this->_helper->layout()->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);

我认为我的助手的结果无论如何都会被解析到我的视图中。严重错误。