During yii application development, we will inevitably use third-party or self-defined css files or js files, so that we need to introduce these files on the page.
During yii application development, we will inevitably use third-party or self-defined css files or js files, so that we need to introduce these files on the page.
Common practice
We usually use the following method to introduce and directly write html code.
Introduce css files
...
...
Introduce js files
Practices in Yii
The CClientScript class is used in Yii to manage css and js files in the view.
Introduce css files
getClientScript()->registerCssFile("/css/main.css"); ?>
Introduce js files
getClientScript()->registerScriptFile("/js/main.js"); ?>
The advantage of using the CClientScript class to introduce files (js/css) is that we can introduce private files of this view into different View files, instead of introducing them in the layout file, which can save resources.
Introduce the built-in script package of the framework
Yii Framework comes with a script, which can be easily used, such as jquery and jquery ui. the usage is as follows:
getClientScript()->registerCoreScript("jquery"); ?>
To introduce the package, you only need to change the package name.
Note: the built-in packages include: 'jquery ', 'yii', 'yiitab', 'iiactiveform', and 'jquery. ui ', 'bgiframe', 'ajaxqueue', 'autocomplete', 'maskedinput', 'cookies', 'treeview', 'multifile', 'rating', 'metadata ', 'BBQ '.