Vra

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>

Was dit nuttig?

Oplossing

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!

Ander wenke

is this what you are looking for?

$this->headScript()->appendFile('/js/isround.js');
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top