1
0

main.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /* @var $this \yii\web\View */
  3. /* @var $content string */
  4. use yii\helpers\Html;
  5. use yii\bootstrap\Nav;
  6. use yii\bootstrap\NavBar;
  7. use yii\widgets\Breadcrumbs;
  8. use frontend\assets\AppAsset;
  9. use common\widgets\Alert;
  10. AppAsset::register($this);
  11. ?>
  12. <?php $this->beginPage() ?>
  13. <!DOCTYPE html>
  14. <html lang="<?= Yii::$app->language ?>">
  15. <head>
  16. <meta charset="<?= Yii::$app->charset ?>">
  17. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  18. <meta name="viewport" content="width=device-width, initial-scale=1">
  19. <?= Html::csrfMetaTags() ?>
  20. <title><?= Html::encode($this->title) ?></title>
  21. <?php $this->head() ?>
  22. </head>
  23. <body>
  24. <?php $this->beginBody() ?>
  25. <div class="wrap">
  26. <?php
  27. NavBar::begin([
  28. 'brandLabel' => Yii::$app->name,
  29. 'brandUrl' => Yii::$app->homeUrl,
  30. 'options' => [
  31. 'class' => 'navbar-inverse navbar-fixed-top',
  32. ],
  33. ]);
  34. $menuItems = [
  35. ['label' => '首页', 'url' => ['/site/index']],
  36. ['label' => '关于', 'url' => ['/site/about']],
  37. ['label' => '联系', 'url' => ['/site/contact']],
  38. ];
  39. if (Yii::$app->user->isGuest) {
  40. $menuItems[] = ['label' => '注册', 'url' => ['/site/signup']];
  41. $menuItems[] = ['label' => '登入', 'url' => ['/site/login']];
  42. } else {
  43. $menuItems[] = '<li>'
  44. . Html::beginForm(['/site/logout'], 'post')
  45. . Html::submitButton(
  46. 'Logout (' . Yii::$app->user->identity->username . ')',
  47. ['class' => 'btn btn-link logout']
  48. )
  49. . Html::endForm()
  50. . '</li>';
  51. }
  52. echo Nav::widget([
  53. 'options' => ['class' => 'navbar-nav navbar-right'],
  54. 'items' => $menuItems,
  55. ]);
  56. NavBar::end();
  57. ?>
  58. <div class="container">
  59. <?= Breadcrumbs::widget([
  60. 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
  61. ]) ?>
  62. <?= Alert::widget() ?>
  63. <?= $content ?>
  64. </div>
  65. </div>
  66. <footer class="footer">
  67. <div class="container">
  68. <p class="pull-left">&copy; <?= Html::encode(Yii::$app->name) ?> <?= date('Y') ?></p>
  69. <p class="pull-right"><?= Yii::powered() ?></p>
  70. </div>
  71. </footer>
  72. <?php $this->endBody() ?>
  73. </body>
  74. </html>
  75. <?php $this->endPage() ?>