开发者

Zend Framework - how to apply my own js plugin?

How can i add my own jQuery plug-in located in my zf path "public/js/isround.js"?

- to apply using Zend framework instead of manually putting this:开发者_运维百科

<script> $("#world").isRound('myPlugin'); </script>
  1. jQuery setup is working

    $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. file application/views/scripts/index/index.phtml, i have:

    < div id="world"> _____my js plugin apply here _____< /div>


is this what you are looking for?

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


Use a view helper. zend documentation Check out: Example #2 Building your own Helper with No Conflict Mode

Also a tutorial about viewhelpers and jquery Zendcast

Here is some code: Create a folder in your library folder called Mylib. In it create a folder views. In views create a folder helpers. In helpers create a file named: IsRound.php

<?php

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

In the indexAction in IndexController.php

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

In index.phtml:

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

Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜