在视图层(../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");批注1:在视图层引用与在控制层引用的方式一样。但在视图层中引用加载的要晚一些。 批注2:引用路径是使用baseUrl,而不是basePath。 批注3:关于参数CClientScript::POS_END,作用是延时加载,提高页面渲染效率。例如: Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/jqueryui/jquery-ui.min.js", CClientScript::POS_END); 全部参数一览: CClientScript::POS_HEAD : the script is inserted in the head section right before the title element. CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section. CClientScript::POS_END : the script is inserted at the end of the body section. CClientScript::POS_LOAD : the script is inserted in the window.onload() function. CClientScript::POS_READY : the script is inserted in the jQuery"s ready function. 注:这些参数仅适用于加载js文件,不适用于加载css文件。三、引入jquery核心部件Yii::app()->clientScript->registerCoreScript("jquery");批注:不论在页面中的何种位置引用,最终yii会将jquery.js文件放入yii的assets文件夹下。即/projectName/assets/82qg58/jquery-1.6.1.min.js。二、在控制层(../controllers/xxController.php)添加CSS文件或JavaScript文件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"); }新增: 在控制层,还可以在ActionIndex中引入,而且还可以引入别的module文件夹中的js/css文件。甚至是任意文件夹下的js/css文件public function actionIndex(){ $modify,$reg = some_value; $js = $this->renderFile($this->getInstallViewPath(). "/asset/install.js",array("reg_mp"=>$reg), true); $js = $this->renderFile($this->getViewPath() . "/assets/install_params.js", array("modify" => $modify), true);