2

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>

2 Answers2

1

is this what you are looking for?

$this->headScript()->appendFile('/js/isround.js');
praethorian
  • 772
  • 1
  • 8
  • 15
  • 1
    Yes, it added the script, but how can i call using ZF. $('#world').isRound('test'); –  Jul 18 '10 at 10:52
0

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!

Iznogood
  • 12,447
  • 3
  • 26
  • 44
  • 1
    there examples are never easy for me, can you show me a example in my case code are like this: http://gist.github.com/480330 –  Jul 18 '10 at 11:14
  • Try watching those tutorials on zendcast they are of immense help and are pretty easy to follow. Ill try to make an exemple later. – Iznogood Jul 18 '10 at 14:47