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.