我已经阅读了很多关于如何注册自定义视图助手的帖子。这不是我的问题。我有自定义视图助手在我的库中工作;但是,它们似乎只能从“默认”模块(即模块外部)访问。尝试从模块中调用帮助程序时,出现以下错误:
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/
如上所述,当我从模块外部进行此调用时,它工作正常......
if ($this->isCurrent(...
但是同一行,在视图脚本中,在模块中会产生错误。
我的助手类在一个名为
library/Sc/View/Helper/IsCurrent.php
类的定义和函数声明如下:
class Sc_View_Helper_IsCurrent extends Zend_View_Helper_Abstract {
public function isCurrent($startTime, $endTime) {
我的 Bootstrap.php 文件(除其他外)包含以下内容:
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");
}
我的 application.ini 文件包含的唯一与模块或视图助手有关的内容是:
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
我尝试注释掉 resources.modules[] 行,因为我在另一篇文章中读到了类似的内容。那只是打破了一切。
我试图从中调用它的特定模块称为“admin”,在该模块的文件夹中是另一个 Bootstrap.php 文件,其中仅包含:
<?php
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
}
关于如何使这个工作视图助手也对我的模块可见的任何建议?