views:

45

answers:

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>

+1  A: 

is this what you are looking for?

$this->headScript()->appendFile('/js/isround.js');
praethorian
Yes, it added the script, but how can i call using ZF. $('#world').isRound('test');
Stackfan
+1  A: 

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
@iznogood, 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
Stackfan
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