1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use backend\assets\AppAsset;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use common\widgets\Alert;
 
//注册this
AppAsset::register($this);
?>
 
//$this->begin/endPage()提供js
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
     
    //未知
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
     
    //$this->begin/endPage() && $this->begin/endBody() && $this->head() 三个标签一起注册CSS
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div>
    <?php
    NavBar::begin([
     
        //文字LOGO区(可无)
        'brandLabel' => 'My Company',
        'brandUrl' => Yii::$app->homeUrl,
         
        //导航样式
        'options' => [
            'class' => 'navbar-inverse navbar-fixed-top',//导航栏处于"顶部"
        ],
    ]);
     
    $menuItems = [
        ['label' => 'Home''url' => ['/site/index']],
    ];
     
    /*设置导航栏*/   
    if (Yii::$app->user->isGuest) {//如果是游客显示请求登录
        $menuItems[] = ['label' => 'Login''url' => ['/site/login']];
    else {
        $menuItems[] = '<li>'
            . Html::beginForm(['/site/logout'], 'post')//因为是post方法提交logout所以用form
            . Html::submitButton(
                'Logout (' . Yii::$app->user->identity->username . ')',//按钮文字
                ['class' => 'btn btn-link']//按钮样式,可以换成其他样式,比如btn btn-danger显示"危险"按钮,网上有bootstrap教程
            )
            . Html::endForm()
            '</li>';
    }
     
    /*设置完毕,显示导航栏*/
    echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],//导航栏样式,靠左?靠右
        'items' => $menuItems,
    ]);
    NavBar::end();
    ?>
    <div>
        //"当前位置"导航
        <?= Breadcrumbs::widget([
            'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
        ]) ?>
         
        //未知作用
        <?= Alert::widget() ?>
         
        //view层替换的是content
        <?= $content ?>
    </div>
</div>
<footer>
    <div>
        <p>&copy; My Company <?= date('Y') ?></p>
        <p><?= Yii::powered() ?></p>
    </div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
posted on 2017-01-08 09:10  longzhankunlun  阅读(231)  评论(0编辑  收藏  举报