CGoogleApi

CDbHttpSession

Yii Framework v1.1.10 类参考

CGoogleApi

system.web.helpers
继承 class CGoogleApi
版本 $Id: CGoogleApi.php 3515 2011-12-28 12:29:24Z mdomba $
源码 framework/web/helpers/CGoogleApi.php
CGoogleApi 提供辅助方法以便用户更加容易的使用谷歌AJAX接口

公共属性

隐藏继承属性

属性类型描述定义在
bootstrapUrl CGoogleApi

公共方法

隐藏继承方法

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

属性详细

bootstrapUrl 属性
public static $bootstrapUrl;

方法详细

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

渲染jsapi脚本文件。

load() 方法
public static string load(string $name, string $version='1', array $options=array ( ))
$name string 模块名
$version string 模块版本
$options array 将被传到load()方法中的额外的js选项。
{return} string 加载模板的js代码。你可以使用 CHtml::script() 把它装入到脚本标签中。
源码: framework/web/helpers/CGoogleApi.php#44 (显示)
public static function load($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)
$name string 模块名
$version string 模块版本
$options array 将被传到load()方法中的额外的js选项。
$apiKey string 接口密钥。如果没有个密钥则为null。
源码: framework/web/helpers/CGoogleApi.php#62 (显示)
public static function register($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脚本,需要加载时调用。

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.