Yii Installation eclientscript plug-in extension implementation css,js file code compression merge loading function _php instance

Source: Internet
Author: User
Tags smarty template yii

This article describes the YII installation eclientscript plug-in extension implementation css,js file code compression merge loading function. Share to everyone for your reference, specific as follows:

Extension download address, after decompression, copy to/protected/vendor/

Https://github.com/muayyad-alsadi/yii-EClientScript

Main configuration file configuration plugin, components inside add

JS,CSS code compression, merging
' ClientScript ' => Array (
 ' class ' => ' Application.vendor.yii-eclientscript.eclientscript ',
 ' combinescriptfiles ' => TRUE,//By default this was set to True, set this to true if you are like "combine" the script files
 ' combinecssfiles ' => true,//by default, S ET to True, set this to true if your ' d like to combine the CSS files
 ' optimizescriptfiles ' =>! Yii_debug,//@since: 1.1
 ' Optimizecssfiles ' =>! Yii_debug,//@since: 1.1
 ' Optimizeinlinescript ' => false,//@since: 1.6, this could case response slower
 ' Optim Izeinlinecss ' => false,//@since: 1.6, this could case response slower
),

Tool class unit.php placed in/protected/vendor/components, class to define the Load method

/**
 * Registration JS file
 *
/Public Function jsfile ($file, $position =cclientscript::P os_head, $media =array ()) {
 $ Cs=yii::app ()->getclientscript ();
 $cs->registerscriptfile ($file, $position, $media);
/**
 * Register CSS File */public
function Cssfile ($file, $media = ') {
 Yii::app ()->getclientscript ()- >registercssfile ($file, $media);
}

Template calls css file, JS file

<?php
//Registration CSS file,
unit::cssfile ('/css/home/base.css ');
Result To:<link rel= "stylesheet" type= "Text/css" href= "/css/home/base.css"/>//ie6 to
load the CSS file unit
:: Cssfile ('/css/form.css ', ' LTE IE 6 ');
Result to:<!--[if LTE IE 6]><link rel= "stylesheet" type= "Text/css" href= "/css/form.css"/><! [endif]-->
//Register JS file,
unit::jsfile ('/js/jquery.lazyload.js ');
Result To:<script src= "/js/jquery.lazyload.js" >
//ie9 Load js file
unit::jsfile ('/js/common.js ', Cclientscript::P os_head, Array (' media ' => ' lt IE 9 '));
Result To:<--[if Lt IE 9]><script src= "/js/common.js" ><! [endif]-->
?>

For more information on YII-related content, readers who are interested in this site can view the topics: Introduction to YII Framework and summary of common skills, "Summary of PHP Excellent development framework", "Smarty Template Introductory Course", "Introduction to PHP object-oriented programming", "PHP string" Summary of Usage , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on the YII framework.

Related Article

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.