I am unsure on how to propperly add a Zend View Helper to my Project.

My project looks like this :

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

My bootstrap file looks like this :

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

My bootstrap file of the module looks like this :

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

}

And finally my application.ini file looks like this :

[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

Now i have a view and in that view i try to call my own made view helper name MyHelper

class Content_View_Helper_MyHelper {

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

When i try and call it in my view by using echo $this->test(); it gives me the error

Plugin by name 'test' was not found in the registry; used paths: 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/

I tried googeling for an answer but sadly none of the answers provided didn't work. Most of them told me to add the helper path trough the bootstrap or in the application.ini however i then recieve an error message about Jquery...

So i'm abit at a loss on how to solve this, any possible solutions would be appreciated :)

有帮助吗?

解决方案

You should use same name for the method also based on the class name last prefix word.

class Content_View_Helper_MyHelper {

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

FYI: View Helpers

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top