2
votes

I've read many posts about how to register a custom view helper. This has not been my issue. I have custom view helpers working from my library; however, they seem to only be accessible from the "default" module (i.e. outside of a module). When attempting to call the helper from within a module, I get the following error:

Message: Plugin by name 'IsCurrent' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/:/Users/firemanrob/Development/Projects/mysite.com/www/application/modules/admin/views/helpers/

As stated above, when I make this call from the outside of a module, it works fine...

if ($this->isCurrent(...

But this same line, in a view script, in a module produces the error.

My helper class is in a file called

library/Sc/View/Helper/IsCurrent.php

The class is defined and function declared as such:

class Sc_View_Helper_IsCurrent extends Zend_View_Helper_Abstract {

public function isCurrent($startTime, $endTime) {

My Bootstrap.php file (among other things) contains this:

function _initViewHelpers() {
    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
    $viewRenderer->setViewSuffix('php');
    unset($viewRenderer);
    /* @var $view Zend_View */
    $view = $layout->getView();
    $options = Zend_Registry::get('options');

    if (Zend_Registry::isRegistered('db')) {
        $this->_db = Zend_Registry::get('db');
    } else {
        $db = $this->getPluginResource('db');
        $this->_db = Zend_Db::factory($db->getAdapter(), $db->getParams());
        Zend_Registry::set('db', $this->_db);
    }

    $view->doctype('HTML5');
    $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
    $view->headTitle($options->template->websiteBaseTitle);
    $view->headTitle()->setSeparator(' | ');
    $view->addHelperPath("Sc/View/Helper", "Sc_View_Helper");

}

The only thing my application.ini file contains, pertaining to modules or view helpers is:

includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

; setup modules

resources.modules[] =
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

;content settings
content.path = "../application/content"

;layout settings

resources.layout.layoutpath = APPLICATION_PATH "/layouts"
resources.layout.viewSuffix = php
resources.layout.layout = "default"

autoloadernamespaces[] = Amg
autoloadernamespaces[] = Sc
autoloadernamespaces[] = Phpmailer

I've tried commenting out the resources.modules[] line, as I read something similar in another post. That just broke everything.

The particular module that I'm trying to call this from is called "admin" and in that module's folder is another Bootstrap.php file that contains only:

<?php
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
}

Any suggestions of how I can make this working view helper visible to my modules as well?

2
Are you doing anything else view related in the bootstrap or application.ini? Can you provide a bit more of the _initViewHelpers function, since what you posted is clearly only part of it.Tim Fountain
Okay Tim, I've added the full function, and pertinent lines of application.ini.kc_rob

2 Answers

2
votes

This is a bit of a long shot, but could you try commenting out the three view renderer lines you currently have and adding the following to the end of your _initViewHelpers() function instead:

$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
$viewRenderer->setViewSuffix('php');
$stack = Zend_Controller_Action_HelperBroker::getStack();
$stack->push($viewRenderer);

This should ensure that the $view object you're configuring is the one that the view renderer uses. Your helper path isn't in the error that you're getting, which suggests this is coming from a different view object.

I don't have an explanation as to why it works in the default module but not the admin one. If it worked from within a layout, but not from a view script that might make a little more sense.

1
votes

It looks like you're using a relative filepath for you view helpers - this could explain why it works when you're in the default module but not in others because in other modules you change the relative path to your view helper is different than when in a module. Try something like $view->addHelperPath("/ABSOLUTE/PATH/TO/library/Sc/View/Helper", "Sc_View_Helper");