0

我不确定如何正确地将 Zend View Helper 添加到我的项目中。

我的项目如下所示:

Project
--application
----configs
----controllers
----layouts
----models
----modules
------content
--------controllers
----------Index
--------forms
--------models
--------views
----------filters
----------helpers
------------myHelper
----------scripts
------------index
----views

我的引导文件如下所示:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function _initViewHelpers()
    {
        $view = new Zend_View();
        $view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewRenderer->setView($view);
        Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
    }
}

我的模块引导文件如下所示:

class Content_Bootstrap extends Zend_Application_Module_Bootstrap {

    public function _initAutoload() {
        $resourceLoader = $this->_resourceAuloloader;

        $autoloader = new Zend_Application_Module_Autoloader(array('namespace' => 'Application',
                                                                    'basePath'  => APPLICATION_PATH));

        Zend_Controller_Action_HelperBroker::addPath(
        APPLICATION_PATH . '/modules/content/controllers/helpers', 'Content_Controller_Helper_');

        return $autoloader;
    }

}

最后我的 application.ini 文件看起来像这样:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

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

resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "****"
resources.db.params.dbname = "database"

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

resources.router.routes.contentroute.route = "/wms/content/:controller/:action/*"
resources.router.routes.contentroute.defaults.module = content
resources.router.routes.contentroute.defaults.controller = index
resources.router.routes.contentroute.defaults.action = index

autoloaderNamespaces[] = "ZendX"

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

现在我有一个视图,在那个视图中我尝试调用我自己制作的视图助手名称 MyHelper

class Content_View_Helper_MyHelper {

    public function test() {
        return 'test';
}

当我尝试通过使用echo $this->test();它在我的视图中调用它时,会出现错误

在注册表中找不到名为“test”的插件;使用的路径: Content_View_Helper_: C:/wamp/www/HPU/application/modules/content/views\helpers/ ZendX_JQuery_View_Helper_: ZendX/JQuery/View/Helper/ Zend_View_Helper_: Zend/View/Helper/

我尝试用谷歌搜索答案,但遗憾的是,所提供的答案都没有奏效。他们中的大多数人告诉我通过引导程序或在 application.ini 中添加辅助路径但是我随后收到关于 Jquery 的错误消息...

所以我对如何解决这个问题有点茫然,任何可能的解决方案都将不胜感激:)

4

1 回答 1

0

您应该根据类名最后一个前缀词为该方法使用相同的名称。

class Content_View_Helper_MyHelper {

    public function MyHelper() {
        return 'test';
}

仅供参考:查看助手

于 2012-06-07T10:14:16.877 回答