【问题标题】:Zend Framework - how to apply my own js plugin?Zend Framework - 如何应用我自己的 js 插件?
【发布时间】:2010-07-17 22:14:58
【问题描述】:

如何在我的 zf 路径“public/js/isround.js”中添加我自己的 jQuery 插件?
- 使用 Zend 框架应用而不是手动放置:

<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. 文件 application/views/scripts/index/index.phtml,我有:

    _____我的 js 插件在这里应用 _____

标签: zend-framework zendx


【解决方案1】:

这就是你要找的吗?

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

【讨论】:

  • 是的,它添加了脚本,但我如何使用 ZF 调用。 $('#world').isRound('test');
【解决方案2】:

使用视图助手。 zend documentation 查看: Example #2 构建你自己的无冲突模式的 Helper

还有一个关于viewhelpers和jquery的教程Zendcast

下面是一些代码: 在您的库文件夹中创建一个名为 Mylib 的文件夹。 在其中创建一个文件夹视图。 在视图中创建一个文件夹助手。 在助手中创建一个名为:IsRound.php

<?php

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

在IndexController.php的indexAction中

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

在 index.phtml 中:

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

希望这会有所帮助!

【讨论】:

  • 这里的例子对我来说从来都不是一件容易的事,你能给我看一个例子吗?我的案例代码是这样的:gist.github.com/480330
  • 尝试观看 zendcast 上的那些教程,它们有很大的帮助,而且很容易理解。稍后我会尝试做一个例子。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-30
  • 1970-01-01
  • 1970-01-01
  • 2015-11-30
  • 1970-01-01
相关资源
最近更新 更多