Package | system.web.helpers |
---|---|
Inheritance | class CGoogleApi |
Since | 1.0.3 |
Version | $Id$ |
Source Code | framework/web/helpers/CGoogleApi.php |
Method | Description | Defined By |
---|---|---|
init() | Renders the jsapi script file. | CGoogleApi |
load() | Loads the specified API module. | CGoogleApi |
register() | Registers the specified API module. | CGoogleApi |
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. |
public static function init($apiKey=null)
{
if($apiKey===null)
return CHtml::scriptFile(self::BOOTSTRAP_URL);
else
return CHtml::scriptFile(self::BOOTSTRAP_URL.'?key='.$apiKey);
}
Renders the jsapi script file.
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. |
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.
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. |
public static function register($name,$version='1',$options=array(),$apiKey=null)
{
$cs=Yii::app()->getClientScript();
$url=$apiKey===null?self::BOOTSTRAP_URL:self::BOOTSTRAP_URL.'?key='.$apiKey;
$cs->registerScriptFile($url);
$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.
Signup or Login in order to comment.