main.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /** @var \yii\web\View $this */
  3. /** @var string $content */
  4. use backend\assets\AppAsset;
  5. use common\widgets\Alert;
  6. use yii\bootstrap4\Breadcrumbs;
  7. use yii\bootstrap4\Html;
  8. use yii\bootstrap4\Nav;
  9. use yii\bootstrap4\NavBar;
  10. AppAsset::register($this);
  11. ?>
  12. <?php $this->beginPage() ?>
  13. <!DOCTYPE html>
  14. <html lang="<?= Yii::$app->language ?>" class="h-100">
  15. <head>
  16. <meta charset="<?= Yii::$app->charset ?>">
  17. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  18. <?php $this->registerCsrfMetaTags() ?>
  19. <title><?= Html::encode($this->title) ?></title>
  20. <?php $this->head() ?>
  21. </head>
  22. <body class="d-flex flex-column h-100">
  23. <?php $this->beginBody() ?>
  24. <header>
  25. <?php
  26. NavBar::begin([
  27. 'brandLabel' => Yii::$app->name,
  28. 'brandUrl' => Yii::$app->homeUrl,
  29. 'options' => [
  30. 'class' => 'navbar navbar-expand-md navbar-dark bg-dark fixed-top',
  31. ],
  32. ]);
  33. $menuItems = [
  34. ['label' => 'Home', 'url' => ['/site/index']],
  35. ];
  36. if (Yii::$app->user->isGuest) {
  37. $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
  38. } else {
  39. $menuItems[] = '<li>'
  40. . Html::beginForm(['/site/logout'], 'post', ['class' => 'form-inline'])
  41. . Html::submitButton(
  42. 'Logout (' . Yii::$app->user->identity->username . ')',
  43. ['class' => 'btn btn-link logout']
  44. )
  45. . Html::endForm()
  46. . '</li>';
  47. }
  48. echo Nav::widget([
  49. 'options' => ['class' => 'navbar-nav'],
  50. 'items' => $menuItems,
  51. ]);
  52. NavBar::end();
  53. ?>
  54. </header>
  55. <main role="main" class="flex-shrink-0">
  56. <div class="container">
  57. <?= Breadcrumbs::widget([
  58. 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
  59. ]) ?>
  60. <?= Alert::widget() ?>
  61. <?= $content ?>
  62. </div>
  63. </main>
  64. <footer class="footer mt-auto py-3 text-muted">
  65. <div class="container">
  66. <p class="float-left">&copy; <?= Html::encode(Yii::$app->name) ?> <?= date('Y') ?></p>
  67. <p class="float-right"><?= Yii::powered() ?></p>
  68. </div>
  69. </footer>
  70. <?php $this->endBody() ?>
  71. </body>
  72. </html>
  73. <?php $this->endPage();