首頁 php教程 PHP开发 Yii安裝EClientScript插件擴充實作css,js檔案程式碼壓縮合併載入功能

Yii安裝EClientScript插件擴充實作css,js檔案程式碼壓縮合併載入功能

Dec 30, 2016 pm 04:24 PM

本文實例講述了Yii安裝EClientScript插件擴充實作css,js檔案程式碼壓縮合併載入功能。分享給大家供大家參考,具體如下:

擴充插件下載位址,解壓縮後複製到/protected/vendor/

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

main設定檔插件外掛,components裡面增加

//js,css代码压缩,合并
'clientScript' => array(
 'class' => 'application.vendor.yii-EClientScript.EClientScript',
 'combineScriptFiles' => TRUE, // By default this is set to true, set this to true if you'd like to combine the script files
 'combineCssFiles' => TRUE, // By default this is set to true, set this to true if you'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 may case response slower
 'optimizeInlineCss' => false, // @since: 1.6, This may case response slower
),
登入後複製

工具類Unit.php放於/protected/vendor/components,類別中定義載入方法

/**
 * 注册JS 文件
 */
public function jsFile($file,$position=CClientScript::POS_HEAD,$media=array()){
 $cs=Yii::app()->getClientScript();
 $cs->registerScriptFile($file,$position,$media);
}
/**
 *注册CSS文件
 */
public function cssFile($file,$media=''){
 Yii::app()->getClientScript()->registerCssFile($file,$media);
}
登入後複製

模板調用css文件,js文件

<?php
//注册CSS文件,
Unit::cssFile(&#39;/css/home/base.css&#39;);
//result to:<link rel="stylesheet" type="text/css" href="/css/home/base.css" />
//IE6下加载CSS文件
Unit::cssFile(&#39;/css/form.css&#39;,&#39;lte IE 6&#39;);
//result to:<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="/css/form.css" /><![endif]-->
//注册JS文件,
Unit::jsFile(&#39;/js/jquery.lazyload.js&#39;);
//result to:<script src="/js/jquery.lazyload.js">
//IE9下加载JS文件
Unit::jsFile(&#39;/js/common.js&#39;, CClientScript::POS_HEAD, array(&#39;media&#39; => &#39;lt IE 9&#39;));
//result to:<--[if lt IE 9]><script src="/js/common.js"><![endif]-->
?>
登入後複製

希望本文所述對大家基於Yii模板調用css文件,js文件

rrreee

希望本文所述對大家基於Yii框架的PHP程式設計有所幫助。

🎜更多Yii安裝EClientScript插件擴充實作css,js檔案程式碼壓縮合併載入功能相關文章請關注PHP中文網! 🎜
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1664
14
CakePHP 教程
1423
52
Laravel 教程
1318
25
PHP教程
1269
29
C# 教程
1248
24