I made a very simple widget, but still encountered some problems
I have the following file structure
int the components dir, there are
views/
views/assets
views/assets/js/(…some js files I want to import)
views/assets/css/(… some css files I want to import)
And now I want to register a css file in the css dir and a js file in the js dir in my widget code
Here is part of the widget code, extended from CWidget class
in the run() method
$this->baseUrl=CHtml::asset(dirname(__FILE__).DIRECTORY_SEPARATOR.'views/assets'); //设置baseUrl,为views/assets
$cs=Yii::app()->clientScript;
$cs->registerScriptFile($this->baseUrl.DIRECTORY_SEPARATOR.'js/javascript.js');//register js file
$cs->registerCssFile($this->baseUrl.DIRECTORY_SEPARATOR.'css/stylesheet.css');//register css file
However, strange things happened.
The css file is successfully registered and it is also published in the asset directory, where jquery core scripts reside, the dir under alias "application".
But the js file failed to register. How could it happen?
The result is :
in
assets/2e47c6a0/css/
there is stylesheet.css, which is what I want to register
and there is an empty js dir, but no files in it.