Revision #3 has been created by David Newcomb on Nov 27, 2014, 1:42:04 PM with the memo:
correct grammer and poor English
« previous (#2) next (#4) »
This tutorial presents a way of separating JS code from views and passing to it values from PHP.
Yii provides two h
* strings prefixed with 'js:'
* CClientScript.registerScript method
[...]* the jQuery object
to extend the global yourPluginName object by adding methods and properties to it, keeping them all in one scope.
Now you can place your bulky JS code from your views inside
such plugin and use them as:
[...]# Namespaced code
By putting all your code in
plugin you keep them in a limited scope and thus create a namespace for it. That helps avoiding name conflicts and keeps your code cleaner.
Another important feature is that
plugin can be registered many times. Sometimes th
happen when you load an action through AJAX on a page that
already registered th
This also allows extending if further, adding more functions.
Also, since there actually is a limited scope, strict mode can be enabled: