无法初始化 Jquery(Zendx) 和 Bootstrap.php 中的视图助手(ZF: 1.10.8)

发布于 2024-10-21 08:52:45 字数 2204 浏览 4 评论 0原文

我无法在 Bootstrap.php(ZF: 1.10.8) 中初始化 Jquery(Zendx) 和 View 帮助程序,

但我能够在每个控制器的 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()
    {


    }


}

请帮助我。提前致谢。

Im unable to initialize Jquery(Zendx) and View helpers in Bootstrap.php(ZF: 1.10.8)

But Im able to initialize the same in every controller's init() method.

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

Following is the error when i run a simple controller,

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

I dont get the same error, if I use the following init() in my controller.

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()
    {


    }


}

Kindly help me out. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜兔 2024-10-28 08:52:45

您可以将视图助手的设置添加到 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;
}

You could add the Setup for your View Helpers to your application.ini (instead of your initView Method):

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

Or if you need your custom bootstrap try to use an "existing view object":

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文