How to use JQuery | JavaScript

[left][font="Arial"]Hi colleagues,

The first thing that I want to know is since i can use JQuery, what options do I have in the moment to write/implement jQuery code?.

Can i do it inline? in the inner of the code of a controller action for example.

If I want to create .js files, where I can put these files if I’m using the template that brings Yii by default?. For example, I should put them inside the folder themes/classic/js? Or inside of the protected folder?

Please I need clear example of how to use jQuery | JavaScript in the scenarios mentioned (or in any other that exists), suggestions, links… taking into consideration the most current version of Yii.

Regards, in advance thank you for the help. And welcome be Yii because you are a marvel (more than you appear).[/font] :D [/left]

Hi Dante,

this depends on what kind of yii component you want to create. For instance, the jformvalidate extension wraps the Validation JQuery plugin into a Yii extension. JS files are distributed in the extension itself, under the js subfolder. When the extension is invoked, it publish the js and then register it.

For instance :




// first publish ...

$am = Yii::app()->getAssetManager();

$am->publish(dirname(__FILE__).DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'jquery.validate.min.js');


// ...then register

$cs=Yii::app()->clientScript;

$cs->registerCoreScript('jquery');

$cs->registerScriptFile();



This is just an example. Hope it helps

ciao