yii中引入js和css文件
作者:zccst
四、在视图层(../views/..)添加CSS文件或JavaScript文件
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/TableView.js");Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/datechooser.js");Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . "/css/datechooser.css");
Yii::app()->clientScript->registerCoreScript('jquery');
public function init(){ //parent::init(); Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css'); Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js');}
<!-- css --><link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/print.css" media="print" /><!-- 图片 --><link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/autocomplete/indicator.gif" /><!-- js --><script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.js"></script>
<?php<!-- (一)简单用法 --><!-- js --> Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/jqueryui/jquery-ui.min.js", CClientScript::POS_END);<!-- (二)复杂用法 -->if($this->user->id) {Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('/account/info', array('format' => 'js')), CClientScript::POS_END);}if($this->user->id) {Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('site/baseJs'));}?>