system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

CJavaScript

system.web.helpers
继承 class CJavaScript
可用自 1.0
版本 $Id$
CJavaScript is a helper class containing JavaScript-related handling functions.

公共方法

隐藏继承的方法

方法描述被定义在
encode() Encodes a PHP variable into javascript representation. CJavaScript
jsonDecode() Decodes a JSON string. CJavaScript
jsonEncode() Returns the JSON representation of the PHP data. CJavaScript
quote() Quotes a javascript string. CJavaScript

方法详情

encode() 方法
public static string encode(mixed $value)
$value mixed PHP variable to be encoded
{return} string the encoded string

Encodes a PHP variable into javascript representation.

Example:

$options=array('key1'=>true,'key2'=>123,'key3'=>'value');
echo CJavaScript::encode($options);
// The following javascript code would be generated:
// {'key1':true,'key2':123,'key3':'value'}


For highly complex data structures use jsonEncode and jsonDecode to serialize and unserialize.

jsonDecode() 方法
public static mixed jsonDecode(string $data, boolean $useArray=true)
$data string the data to be decoded
$useArray boolean whether to use associative array to represent object data
{return} mixed the decoded PHP data

Decodes a JSON string.

jsonEncode() 方法
public static string jsonEncode(mixed $data)
$data mixed the data to be encoded
{return} string the JSON representation of the PHP data.

Returns the JSON representation of the PHP data.

quote() 方法
public static string quote(string $js, boolean $forUrl=false)
$js string string to be quoted
$forUrl boolean whether this string is used as a URL
{return} string the quoted string

Quotes a javascript string. After processing, the string can be safely enclosed within a pair of quotation marks and serve as a javascript string.