Yii 加载css
Yii::app()->getClientScript()->registerCssFile(Yii::app()->baseUrl.'/css/login.css');
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/login.js');
这样是直接获取css ,js 获得的结果为模块根目录
1 <?php 2 class Controller extends CController{ 3 private $_assetsUrl; 4 public function getAssetsUrl(){ 5 if($this->_assetsUrl===null){ 6 $baseUrl = Yii::getPathOfAlias('application.static'); 7 $this->_assetsUrl=Yii::app()->getAssetManager()->publish($baseUrl, false, -1, YII_DEBUG); 8 return $this->_assetsUrl; 9 } 10 } 11 public function setAssetsUrl($value){ 12 $this->_assetsUrl = $value; 13 } 14 15 }
这样将把protected/static 里的文件复制到assets/XXXX里。
调用时直接这样: <link rel="stylesheet" type="text/css" href="<?php echo $this->assetsUrl;?>/css/lib.css" />