无法将jQuery加载到Zend框架项目

时间:2012-03-27 07:53:48

标签: jquery zend-framework load

我想将jQuery加载到现有项目中,我确信ZendX存在于库项目中的extras / library中。

我将这两行添加到application.ini

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

然后在bootstrap文件中我添加了这个方法

protected function _initViewHelpers() {
    $view = $this->getResource('view');
    $view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
    $view->jQuery()->addStylesheet('/css/ui-lightness/jquery-ui-1.8.18.custom.css')
            ->setLocalPath('/js/jquery-1.7.1.min')
            ->setUiLocalPath('/js/jquery-ui-1.8.18.custom.min.js');
 }

我确信从jquery和css文件的路径。    在layout.phtml中我添加了这一行

 echo $this->jQuery;

但是这个错误发生了

  Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'JQuery' was not found in the registry; 
used paths: ZendX_JQuery_View_Helper_: ZendX/JQuery/View/Helper/ Zend_View_Helper_: Zend/View/Helper/' in E:\GCC\ZendFramework-1.11.11\library\Zend\Loader\PluginLoader.php:412
 Stack trace: #0 E:\GCC\ZendFramework-1.11.11\library\Zend\View\Abstract.php(1182): Zend_Loader_PluginLoader->load('JQuery') 
 #1 E:\GCC\ZendFramework-1.11.11\library\Zend\View\Abstract.php(618): Zend_View_Abstract->_getPlugin('helper', 'jQuery') 
 #2 E:\GCC\ZendFramework-1.11.11\library\Zend\View\Abstract.php(344): Zend_View_Abstract->getHelper('jQuery')
 #3 [internal function]: Zend_View_Abstract->__call('jQuery', Array) 
 #4 C:\AppServ\www\zendApps\inspection\application\Bootstrap.php(38): Zend_View->jQuery()
 #5 E:\GCC\ZendFramework-1.11.11\library\Zend\Application\Bootstrap\BootstrapAbstract.php(669): Bootstrap->_initViewHelpers() 
 #6 E:\GCC\ZendFramework-1.11.11\library\Zend\Application\Bootstrap\BootstrapAbstract.php in E:\GCC\ZendFramework-1.11.11\library\Zend\Loader\PluginLoader.php on line 412

2 个答案:

答案 0 :(得分:0)

尝试echo $this->jQuery();代替jQuery

您不需要注册两次jQuery帮助程序路径。 application.ini中的一次就足够了。

此外,在从引导程序获取资源之前,始终确保此资源在使用$this->boostrap('view');之前已被“提升”。

答案 1 :(得分:0)

在“layout.phtml”中添加以下内容:

$this->jQuery()->enable(); //enabling jquery
$this->jQuery()->uiEnable(); //enabling jquery-ui
echo $this->jQuery(); //

- 或 -

在“_initViewHelpers()”的末尾添加:

$view->jQuery()->enable(); //enabling jquery for all the views
$view->jQuery()->uiEnable(); //enabling jquery-ui for all the views

然后在每个视图或布局的head部分中:

<?php echo $this->jQuery(); ?> //dont forget the () or it will not recognize the helper