### 靜態資源引用
>[danger] Yii自帶的Assets功能極大的增加了學習成本,因此暫定去除此功能。
>請參考 http://www.yiichina.com/doc/guide/2.0/structure-assets
1. 明確web目錄下assets、css、js、images這幾個目錄的作用。
2. 新建web\lib目錄,把第三方資源庫放到這個目錄中。
3. 修改母版頁代碼。
~~~
//AppAsset::register($this);
# 頭部
<?php $this->head() ?>
<?= Html::cssFile('@web/lib/bootstrap/css/bootstrap.min.css') ?>
<?= Html::cssFile('@web/css/bootstrap-theme.css') ?>
<?= Html::cssFile('@web/css/site.css') ?>
# 尾部
<?= Html::jsFile('@web/lib/jquery/jquery.min.js') ?>
<?= Html::jsFile('@web/lib/bootstrap/js/bootstrap.min.js') ?>
<?= Html::jsFile('@web/lib/yii/yii.js') ?>
<?= Html::jsFile('@web/lib/yii/yii.activeForm.js') ?>
<?= Html::jsFile('@web/lib/yii/yii.validation.js') ?>
<?= Html::jsFile('@web/js/site.js') ?>
<?php if (isset($this->blocks['script'])): ?>
<?= $this->blocks['script'] ?>
<?php endif ?>
<?php $this->endBody() ?>
</body>
~~~
### 改造Navbar
>[success] 避免使用Widgets控件,盡量做到前后端分離。
~~~
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a href="<?= Yii::$app->homeUrl ?>" class="navbar-brand">My Company</a>
</div>
<ul class="nav navbar-nav navbar-right">
...
</ul>
</div>
</nav>
~~~
### 數據塊
默認數據塊:$content
自定義數據塊:
1、在母版頁中
~~~
<?php if (isset($this->blocks['script'])): ?>
<?= $this->blocks['script'] ?>
<?php else: ?>
... 默認內容 ...
<?php endif ?>
~~~
2、在內容View中
~~~
<?php $this->beginBlock('script'); ?>
...content of script block...
<?php $this->endBlock(); ?>
~~~