[TOC]
#### 1. 使用AssetBundle進行注冊
~~~
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/product_release.css',
'css/main.css',
'css/center.css',
];
public $js = [
'js/common.js'
];
public $depends = [
'yii\web\JqueryAsset',
'light\assets\LayerAsset',
];
}
~~~
在view中使用asset進行注冊
~~~
<?php AppAsset::register($this); ?>
~~~
#### 2.View中直接注冊JS 、CSS文件
~~~
//注冊JS文件
<?php $this->registerJsFile('/js/product_attr.js'); ?>
//注冊JS文件,并設置依賴優先關系,如下,jquery文件會優先加載。
<?php $this->registerJsFile('/js/product_attr.js',['depends'=>['yii\web\JqueryAsset']]); ?>
//注冊CSS文件
<?php $this->registerCssFile('/css/cart.css'); ?>
//注冊CSS文件,設置依賴優先關系,如下,AppAsset的css文件會優先加載。
<?php $this->registerCssFile('/css/cart.css',['depends'=>['backend\assets\AppAsset']]); ?>
~~~
#### 3.View中使用JS、CSS代碼塊
~~~
//注冊JS代碼塊
<?php $this->beginBlock('js'); ?>
function mytest(){
alert('hello wangkun');
}
<?php $this->endBlock(); ?>
<?php $this->registerJs($this->blocks['js'],View::POS_END); ?>
//注冊CSS代碼塊
<?php
$cssStr = ".text-block{background-color:red;}";
$this->registerCss($cssStr);
?>
~~~
- 基礎教程
- 入門安裝
- Yii2 composer 安裝慢解決
- Cookies
- 數據庫操作
- 數據提供者
- 助手類
- 驗證規則
- GridView
- DetailView
- YII2分頁
- JS、CSS的引用
- Excel導出
- 中文轉拼音
- 發送郵件
- 第三方插件
- Session跨域共享
- Url跨域訪問
- 場景應用
- 查詢條件鏈
- Session分布式共享
- Redis的使用
- mongodb
- 高級教程
- 自定義gii模板
- 角色權限管理(RBAC)
- user組件的配置
- 國際化(I18N)
- 小部件(Widget)
- 模塊(Module)
- 行為(Behavior)
- 緩存(Cache)
- migrate 數據庫遷移
- phpstorm
- 快捷鍵
- 自定義
- 其它插件