簡體   English   中英

Zend View Helper在模塊中不可用

[英]Zend view helper not available in module

我已經閱讀了許多有關如何注冊自定義視圖助手的文章。 這不是我的問題。 我的圖書館中有自定義視圖助手。 但是,它們似乎只能從“默認”模塊(即模塊外部)進行訪問。 嘗試從模塊內調用幫助程序時,出現以下錯誤:

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

關於如何使該工作視圖助手對模塊也可見的任何建議?

這有點長,但是您可以嘗試注釋掉當前擁有的三個視圖渲染器行,然后在_initViewHelpers()函數的末尾添加以下內容:

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

這應該確保您配置的$view對象是視圖渲染器使用的對象。 您的幫助程序路徑沒有出現錯誤,這表明此錯誤來自其他視圖對象。

我沒有解釋為什么它在默認模塊中起作用,但在管理模塊中卻沒有。 如果它是在布局內工作的,而不是從視圖腳本工作的,那可能會更有意義。

看來您在使用視圖助手的相對文件路徑-這可以解釋為什么當您使用默認模塊而不是其他模塊時它可以工作,因為在其他模塊中,您更改視圖助手的相對路徑不同於在一個模塊中。 嘗試類似$view->addHelperPath("/ABSOLUTE/PATH/TO/library/Sc/View/Helper", "Sc_View_Helper");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM