Versions
Look up a class, method, property or event

CGoogleApi

Package system.web.helpers
Inheritance class CGoogleApi
Source Code framework/web/helpers/CGoogleApi.php
CGoogleApi provides helper methods to easily access the Google API loader.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
bootstrapUrl string Protocol relative url to the Google API loader which allows easy access to most of the Google AJAX APIs CGoogleApi

Public Methods

Hide inherited methods

MethodDescriptionDefined By
init() Renders the jsapi script file. CGoogleApi
load() Loads the specified API module. CGoogleApi
register() Registers the specified API module. CGoogleApi

Property Details

bootstrapUrl property
public static string $bootstrapUrl;

Protocol relative url to the Google API loader which allows easy access to most of the Google AJAX APIs

Method Details

init() method
public static string init(string $apiKey=NULL)
$apiKey string the API key. Null if you do not have a key.
{return} string the script tag that loads Google jsapi.
Source Code: framework/web/helpers/CGoogleApi.php#30 (show)
public static function init($apiKey=null)
{
    if(
$apiKey===null)
        return 
CHtml::scriptFile(self::$bootstrapUrl);
    else
        return 
CHtml::scriptFile(self::$bootstrapUrl.'?key='.$apiKey);
}

Renders the jsapi script file.

load() method
public static string load(string $name, string $version='1', array $options=array ( ))
$name string the module name
$version string the module version
$options array additional js options that are to be passed to the load() function.
{return} string the js code for loading the module. You can use CHtml::script() to enclose it in a script tag.
Source Code: framework/web/helpers/CGoogleApi.php#47 (show)
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).");";
}

Loads the specified API module. Note that you should call init first.

register() method
public static void register(string $name, string $version='1', array $options=array ( ), string $apiKey=NULL)
$name string the module name
$version string the module version
$options array additional js options that are to be passed to the load() function.
$apiKey string the API key. Null if you do not have a key.
Source Code: framework/web/helpers/CGoogleApi.php#65 (show)
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,CClientScript::POS_HEAD);

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

Registers the specified API module. This is similar to load except that it registers the loading code with CClientScript instead of returning it. This method also registers the jsapi script needed by the loading call.

Total 1 comment

#2384 report it
Francis.TM at 2010/12/21 03:39am
Register GoogleMAP V3 API

To register GMap API V3 by CGoogleApi::register(), you should do like this:

CGoogleApi::register('maps', '3', array('other_params' => 'sensor=false'));

Be Advise: 'senor=false' there's no space.

Detailed according to http://code.google.com/p/yii/issues/detail?id=1590

Leave a comment

Please to leave your comment.