将Zend View Helpers和Jquery分配给模块

时间:2012-06-06 15:29:56

标签: jquery zend-framework module helpers zend-view

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

我的项目如下:

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

我的bootstrap文件如下所示:

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

我的模块的bootstrap文件如下所示:

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:/瓦帕/网络/ HPU /应用/模块/内容/视图\助手/   ZendX_JQuery_View_Helper_:ZendX / JQuery / View / Helper /   Zend_View_Helper_:Zend / View / Helper /

我试着googeling寻找答案,但很遗憾没有提供的答案没有用。他们中的大多数告诉我通过引导程序或在application.ini中添加帮助程序路径然后我收到有关Jquery的错误消息......

所以我不知道如何解决这个问题,任何可能的解决方案都会受到赞赏:)

1 个答案:

答案 0 :(得分:0)

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

class Content_View_Helper_MyHelper {

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

仅供参考:View Helpers