CGoogleApi

优质
小牛编辑
125浏览
2023-12-01
所有包 | 属性 | 方法
system.web.helpers
继承class CGoogleApi
版本$Id: CGoogleApi.php 3515 2011-12-28 12:29:24Z mdomba $
源码framework/web/helpers/CGoogleApi.php
CGoogleApi 提供辅助方法以便用户更加容易的使用谷歌AJAX接口。

公共属性

隐藏继承属性

属性类型描述定义在
bootstrapUrlCGoogleApi

公共方法

隐藏继承方法

方法描述定义在
init()渲染jsapi脚本文件。CGoogleApi
load()加载指定的接口模块。CGoogleApi
register()注册指定的接口模块。CGoogleApi

属性详细

bootstrapUrl 属性 public static $bootstrapUrl;

方法详细

init() 方法
public static string init(string $apiKey=NULL)
$apiKeystring接口密钥。如果没有个密钥则为null。
{return}string加载的谷歌jsapi的脚本连接。
源码: framework/web/helpers/CGoogleApi.php#27 (显示) publicstaticfunctioninit($apiKey=null)
{
if($apiKey===null)
returnCHtml::scriptFile(self::$bootstrapUrl);
else
returnCHtml::scriptFile(self::$bootstrapUrl.'?key='.$apiKey);
}

渲染jsapi脚本文件。

load() 方法
public static string load(string $name, string $version='1', array $options=array ( ))
$namestring模块名
$versionstring模块版本
$optionsarray将被传到load()方法中的额外的js选项。
{return}string加载模板的js代码。你可以使用 CHtml::script() 把它装入到脚本标签中。
源码: framework/web/helpers/CGoogleApi.php#44 (显示) publicstaticfunctionload($name,$version='1',$options=array())
{
if(empty($options))
return"google.load("{$name}","{$version}");";
else
return"google.load("{$name}","{$version}",".CJavaScript::encode($options).");";
}

加载指定的接口模块。 注意,你应该首先调用init方法。

register() 方法
public static void register(string $name, string $version='1', array $options=array ( ), string $apiKey=NULL)
$namestring模块名
$versionstring模块版本
$optionsarray将被传到load()方法中的额外的js选项。
$apiKeystring接口密钥。如果没有个密钥则为null。
源码: framework/web/helpers/CGoogleApi.php#62 (显示) publicstaticfunctionregister($name,$version='1',$options=array(),$apiKey=null)
{
$cs=Yii::app()->getClientScript();
$url=$apiKey===null?self::$bootstrapUrl:self::$bootstrapUrl.'?key='.$apiKey;
$cs->registerScriptFile($url);

$js=self::load($name,$version,$options);
$cs->registerScript($name,$js,CClientScript::POS_HEAD);
}

注册指定的接口模块。 这个类似于 load ,只不过这个是注册加载的代码。 用 CClientScript 代替返回。 这个方法也注册jsapi脚本,需要加载时调用。