2010-07-17 16 views
2

如何添加我自己的jQuery插件位於我的zf路徑「public/js/isround.js」?
- 使用Zend Framework應用的手動把這個改爲:Zend Framework - 如何應用我自己的js插件?

<script> $("#world").isRound('myPlugin'); </script> 
  1. jQuery的設置工作

    $this->jQuery()->setLocalPath('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js') 
           ->enable() 
           ->setUiLocalPath('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js') 
           ->uiEnable() 
           ->addStylesheet('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/ui-lightness/jquery-ui.css'); 
    
  2. 文件的應用程序/視圖/腳本/指數/ index.phtml,我有:

    < div id =「world」> _____my js插件在這裏適用_____ </div>

回答

1

使用視圖助手。 zend documentation 退房: 例2中無衝突模式

兼論viewhelpers和jQuery Zendcast

這裏教程建立自己的助手是一些代碼: 創建一個名爲MYLIB庫中的文件夾中的文件夾。 在其中創建一個文件夾視圖。 在視圖中創建文件夾助手。在IndexController.php

$this->view->addHelperPath('Mylib/views/helpers', 'Mylib_Views_Helpers'); 

IsRound.php

<?php 

class Mylib_Views_Helpers_IsRound { 
    public function isRound($elem){ 
     echo '<script type="text/javascript">$("'.$elem.'").isRound();</script>'; 
    } 
} 

在的indexAction在index.phtml: 在助手創建一個文件名爲

<?php $this->isRound('#elem'); ?> 

希望這有助於!

+1

那裏的例子對我來說不會容易,你能告訴我一個例子,在我的情況下代碼是這樣的:http://gist.github.com/480330 – YumYumYum 2010-07-18 11:14:29

+0

嘗試看zendcast的這些教程,他們是巨大的幫助,很容易跟隨。我試着稍後做一個例子。 – Iznogood 2010-07-18 14:47:03

2

這是你在找什麼?

$this->headScript()->appendFile('/js/isround.js'); 
+1

是的,它添加了腳本,但我怎樣才能使用ZF調用。 $('#世界)isRound( '測試')。 – YumYumYum 2010-07-18 10:52:15

相關問題