Difference between #1 and #2 of
Clean JavaScript code in your views

Revision #2 has been created by nineinchnick on Aug 30, 2013, 8:28:00 PM with the memo:

fixed typos, adjusted first paragraph
« previous (#1) next (#3) »


Title unchanged

Clean JavaScript code in your views

Category unchanged


Yii version unchanged

Tags unchanged

javascript, registerScript, CClientScript, js

Content changed

This tutorial presents a way of separating JS code from views and passing to it values from PHP.
Yii provides two handful ways of keeping JavaScript code close to the widgets and other elements they interact with:

* strings prefixed with 'js:'
"use strict";
// private var
var _settings;
    // public var
    yourPluginName.someProperty = 'default value';
// public method appEdityourPluginName.init = function(settings) {
_settings = $.extend({}, settings);

The '_settings' var is private and can be only referenced inside functions defined in yourPluginName;
Now your PHP and JS code is: * separated and cleaner * safer * easier to read * more extensible (no more hardcoded labels and urls in JS!)
18 0
Viewed: 37 597 times
Version: 1.1
Category: Tutorials
Written by: nineinchnick
Last updated by: samdark
Created on: Aug 30, 2013
Last updated: 2 years ago
Update Article


View all history