Encodes a PHP variable into javascript representation.
Example:
$options['onLoading'] = "doit";
$options['onComplete'] = "more";
//expects the following javascript code
// {'onLoading':'doit','onComplete':'more'}
For higher complexity data structures use jsonEncode and jsonDecode to serialize and unserialize.
static
string
encode
(mixed $value, [boolean $toMap = true], [boolean $encodeEmptyStrings = false])
-
mixed
$value: PHP variable to be encoded
-
boolean
$toMap: whether the output is a map or a list.
-
boolean
$encodeEmptyStrings: wether to encode empty strings too. Default to false for BC.
Deprecated, use isJsLiteral instead
static
void
isFunction
( $js)
static
boolean
isJsLiteral
( $js)
Minimize the size of a javascript script.
This method is based on Douglas Crockford's JSMin.
static
minimized
JSMin
(string $code)
-
string
$code: code that you want to minimzie
Decodes a javascript string into PHP variable.
This method invokes json_decode to perform the decoding.
static
mixed
jsonDecode
(string $value, [bool $assoc = false], [int $depth = 512])
-
string
$value: string to be decoded
-
bool
$assoc: whether to convert returned objects to associative arrays
-
int
$depth: recursion depth
Encodes a PHP variable into javascript string.
This method invokes json_encode to perform the encoding.
static
string
jsonEncode
(mixed $value, [ $options = 0])
-
mixed
$value: variable to be encoded
-
$options
Deprecated, use quoteJsLiteral instead
static
void
quoteFunction
( $js)
static
Marks
quoteJsLiteral
( $js)
Quotes a javascript string.
After processing, the string is safely enclosed within a pair of quotation marks and can serve as a javascript string.
static
string
quoteString
(string $js)
-
string
$js: string to be quoted
Renders javascript block
static
string
renderScriptBlock
(string $script)
-
string
$script: javascript block
Renders a list of javascript blocks
static
string
renderScriptBlocks
(array $scripts)
-
array
$scripts: javascript blocks
Renders a javascript file
static
string
renderScriptFile
(string $file)
-
string
$file: URL to the javascript file
Renders a list of javascript files
static
string
renderScriptFiles
(array $files)
-
array
$files: URLs to the javascript files