php yii asset资源配置

sunyu0 2014-06-23

1.配置文件

'clientScript'=>array(  
    'coreScriptUrl'=>'/js', // required to prevent asset publishing of core scripts  
    'scriptMap'=>array(  
    //'*.js'=>false,   
       'jquery.js'=>false, //特定的  
    //'*.css'=>false,  
    ),  
),

2.把js放到最后或最前加载

<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/js/libs/jquery-ui-datetimepicker.js', CClientScript::POS_BEGIN); ?>最前

<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/js/libs/jquery-ui-datetimepicker.js', CClientScript::POS_END); ?>最后

3.资源路径

'assetManager'=>array(
             // 改变磁盘上的路径
            'basePath'=>dirname(__FILE__).'/../../assets/',
             // 改变url
             'baseUrl'=>'/web/assets/'
 ),

4.js,css,images放到asset目录下

stylesheet目录
js存放js文件
css存放css文件
images存放图片

$assets = Yii::app()->basePath."/../stylesheet";
Yii::app()->params['sourceurl'] = Yii::app()->assetManager->publish($assets, false, -1, YII_DEBUG); 
		  
Yii::app()->clientScript->registerCssFile(Yii::app()->params['sourceurl'].'/css/index.css');

Yii::app()->clientScript->registerCssFile(Yii::app()->params['sourceurl'].'/css/index.js');

相关推荐