Yii introduces css files and js files

Source: Internet
Author: User
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 '.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.