RegisterPackage 依赖于 RegisterScriptFile [英] RegisterPackage depends on RegisterScriptFile

查看:56
本文介绍了RegisterPackage 依赖于 RegisterScriptFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要 Google 地图库的包.我在视图中是这样实现的.

I have a package that requires Google Map library. And I implemented it like this in the view.

<?php Yii::app()->clientScript->registerScriptFile('http://maps.googleapis.com/maps/api/js?sensor=false&language=' . Yii::app()->language . '&region='.Yii::app()->language, CClientScript::POS_HEAD); ?>
<?php Yii::app()->clientScript->registerPackage('somelibrary'); ?>

(注意谷歌地图库需要一个参数Yii::app()->language).

(Note that the Google Map library needs a parameter Yii::app()->language).

但在输出中,包总是放在谷歌地图的上方.

But in the output, the package is always placed above the google maps.

<script type="text/javascript" src="/project/assets/74e60422/somelibrary.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;language=id&amp;region=id"></script>

是否有任何解决方案可以将 Google 地图库作为包依赖项?或者,至少,如何将 somelibrary 包放在谷歌地图之后(不远处)?

Is there any solution to make the Google Maps library as the package dependency? Or, at least, how to place the somelibrary package right after (not far below) the google maps ?

推荐答案

您可以通过配置 packages CClientScript 的属性.然后,您可以通过在包配置中配置depends"来将 googlemap 添加到您的包依赖项中.然后应该以正确的顺序添加脚本.

You can make the google map script a package itself by configuring the packages property of CClientScript. Then you can add the googlemap to your packages dependencies by configuring 'depends' in the package configuration. This should then add the scripts in the correct order.

要添加包,您可以执行以下操作(没有尝试过,但应该可以):

To add a package you can do the following (didn't try that, but should work):

Yii::app()->clientScript->addPackage('googleMap', array(
    'baseUrl'=>'http://maps.googleapis.com/maps/api',
    'js'=>array('js?sensor=false&language=' . Yii::app()->language . '&region='.Yii::app()->language)
));

相同的 'googleMap'=>array(/*...*/) 将在您将其放入配置中时起作用.

Same 'googleMap'=>array(/*...*/) will work when you put it in your configuration.

这篇关于RegisterPackage 依赖于 RegisterScriptFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆