RegisterPackage depends on RegisterScriptFile

后端 未结 2 1233
一个人的身影
一个人的身影 2021-01-19 09:06

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

clientScript->registerScriptFile(\'         


        
2条回答
  •  死守一世寂寞
    2021-01-19 09:36

    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 . '®ion='.Yii::app()->language)
    ));
    

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

提交回复
热议问题