main.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /** @var \yii\web\View $this */
  3. /** @var string $content */
  4. use common\widgets\Alert;
  5. use frontend\assets\AppAsset;
  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. ['label' => 'About', 'url' => ['/site/about']],
  36. ['label' => 'Contact', 'url' => ['/site/contact']],
  37. ];
  38. if (Yii::$app->user->isGuest) {
  39. $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
  40. $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
  41. } else {
  42. $menuItems[] = '<li>'
  43. . Html::beginForm(['/site/logout'], 'post', ['class' => 'form-inline'])
  44. . Html::submitButton(
  45. 'Logout (' . Yii::$app->user->identity->username . ')',
  46. ['class' => 'btn btn-link logout']
  47. )
  48. . Html::endForm()
  49. . '</li>';
  50. }
  51. echo Nav::widget([
  52. 'options' => ['class' => 'navbar-nav ml-auto'],
  53. 'items' => $menuItems,
  54. ]);
  55. NavBar::end();
  56. ?>
  57. </header>
  58. <main role="main" class="flex-shrink-0">
  59. <div class="container">
  60. <?= Breadcrumbs::widget([
  61. 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
  62. ]) ?>
  63. <?= Alert::widget() ?>
  64. <?= $content ?>
  65. </div>
  66. </main>
  67. <footer class="footer mt-auto py-3 text-muted">
  68. <div class="container">
  69. <p class="float-left">&copy; <?= Html::encode(Yii::$app->name) ?> <?= date('Y') ?></p>
  70. <p class="float-right"><?= Yii::powered() ?></p>
  71. </div>
  72. </footer>
  73. <?php $this->endBody() ?>
  74. </body>
  75. </html>
  76. <?php $this->endPage();