2010-07-17 18 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

相关问题