Yii安裝EClientScript插件擴充實作css,js檔案程式碼壓縮合併載入功能
本文實例講述了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('/css/home/base.css'); //result to:<link rel="stylesheet" type="text/css" href="/css/home/base.css" /> //IE6下加载CSS文件 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]--> //注册JS文件, Unit::jsFile('/js/jquery.lazyload.js'); //result to:<script src="/js/jquery.lazyload.js"> //IE9下加载JS文件 Unit::jsFile('/js/common.js', CClientScript::POS_HEAD, array('media' => 'lt IE 9')); //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
人工智慧驅動的應用程序,用於創建逼真的裸體照片

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

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

熱門文章
<🎜>:種植花園 - 完整的突變指南
3 週前
By DDD
<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
如何修復KB5055612無法在Windows 10中安裝?
3 週前
By DDD
北端:融合系統,解釋
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
藍王子:如何到達地下室
1 個月前
By DDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

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