4

I have a problem with accessing a custom view helper in a view. Call the helper in the layout.phtml works perfectly.

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

}

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;
    }
}

View:

<?php
    echo $this->loader();
?>

Error:

Plugin by name 'Loader' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/

Why can't I use the helper in my view?

uniqueHxC
  • 41
  • 6

2 Answers2

0

Perhaps try explicitly adding your view to the view renderer:

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

I can't quite recreate your problem - having it work in the layout but not the view.

If I add a view resource to the application.ini, some of the wiring happens automagically for me in ZF 1.11.14, but if I create the view (new Zend_View) in the bootstrap as a resource I have to explicitly pass it to the view renderer.

Progrock
  • 7,373
  • 1
  • 19
  • 25
0

Fixed it.

The problem were the following lines in my action:

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

I thought the result of my helper would be parsed into my view anyway. Bad mistake.

uniqueHxC
  • 41
  • 6