1

我无法在 Bootstrap.php(ZF:1.10.8)中初始化 Jquery(Zendx)和查看助手

但我能够在每个控制器的 init() 方法中初始化相同的。

//我的 Bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    protected function _initView()
    {
            $view = new Zend_View();
            $view->doctype('XHTML1_STRICT');
        $view->addHelperPath('Vapps/View/Helper/','Vapps_View_Helper');
        $view->addHelperPath('ZendX/JQuery/View/Helper','ZendX_JQuery_View_Helper');
            return $view;
    }
}

以下是我运行简单控制器时的错误,

Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'JQuery' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/:/opt/lampp/htdocs/schooldir/application/views/helpers/' in /opt/lampp/htdocs/schooldir/library/Zend/Loader/PluginLoader.php:412 Stack trace: #0 /opt/lampp/htdocs/schooldir/library/Zend/View/Abstract.php(1174): Zend_Loader_PluginLoader->load('JQuery') #1 /opt/lampp/htdocs/schooldir/library/Zend/View/Abstract.php(610): Zend_View_Abstract->_getPlugin('helper', 'jQuery') #2 /opt/lampp/htdocs/schooldir/library/Zend/View/Abstract.php(336): Zend_View_Abstract->getHelper('jQuery') #3 [internal function]: Zend_View_Abstract->__call('jQuery', Array) #4 /opt/lampp/htdocs/schooldir/application/layouts/scripts/layout.phtml(29): Zend_View->jQuery() #5 /opt/lampp/htdocs/schooldir/library/Zend/View.php(108): include('/opt/lampp/htdo...') #6 /opt/lampp/htdocs/schooldir/library/Zend/View/Abstract.php(880): Zend_View->_run('/opt/lampp/htdo...') #7 /opt/lamp in /opt/lampp/htdocs/schooldir/library/Zend/Loader/PluginLoader.php on line 412

如果我在控制器中使用以下 init(),我不会收到相同的错误。

class ViewhelperexampleController extends Zend_Controller_Action
{


    public function init() {

    $this->view->addHelperPath('ZendX/JQuery/View/Helper','ZendX_JQuery_View_Helper');
    $this->view->addHelperPath('Vapps/View/Helper/','Vapps_View_Helper');


    }



    public function indexAction()
    {


    }


}

请帮帮我。提前致谢。

4

1 回答 1

1

您可以将 View Helpers 的设置添加到您的 application.ini (而不是您的 initView 方法):

resources.view.helperPath.ZendX_JQuery_View_Helper = "ZendX/JQuery/View/Helper"
pluginPaths.ZendX_Application_Resource = "ZendX/Application/Resource"

或者,如果您需要自定义引导程序,请尝试使用“现有视图对象”:

protected function _initView()
{       
   $this->bootstrap('view'); 
   $view = $this->getResource('view');
   $view->doctype('XHTML1_STRICT');

   // better use " instead of ' , seems to be an bug
   $view->addHelperPath("Vapps/View/Helper/",'Vapps_View_Helper');
   $view->addHelperPath("ZendX/JQuery/View/Helper",'ZendX_JQuery_View_Helper');
   return $view;
}
于 2011-03-13T10:55:22.620 回答