2012-03-27 82 views
1

我想將jQuery加載到現有項目中,我相信ZendX存在於庫項目中的extras/library中。無法將jQuery加載到Zend框架項目

我添加以下兩行的application.ini

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

然後在引導文件我添加此方法

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; 

,但這個錯誤occor

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 
+0

你解決了你的問題嗎? – Liyali 2012-04-04 05:04:50

回答

0

嘗試echo $this->jQuery();而不是jQuery

您不需要註冊兩次jQuery幫助器路徑。有一次在application.ini中應該足夠了。

此外,在從引導程序獲取資源之前,始終保留確保此資源已被「提升」,並且之前的版本號爲:$this->boostrap('view');

+0

它不起作用,jQuery是變量,但jQuery()是一種方法,它不方便工作; – palAlaa 2012-03-27 11:34:42

+0

您/ ZendX /目錄位於/ library /目錄下,對嗎?如果你在'ZendX_Application_Resource_Jquery'中var_dump()'something或'die;',這個類至少被調用了什麼? – Liyali 2012-03-29 04:45:39

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 

然後在您的每個視圖或佈局的頭部分中:

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