Commit 1942306050347d442cc93fb86ea60dbdd08b4973
1 parent
6be43b62
+ 1-уровневое меню на frontend
Showing
5 changed files
with
63 additions
and
60 deletions
Show diff stats
common/models/Menu.php
| @@ -17,6 +17,29 @@ use Yii; | @@ -17,6 +17,29 @@ use Yii; | ||
| 17 | */ | 17 | */ |
| 18 | class Menu extends \yii\db\ActiveRecord | 18 | class Menu extends \yii\db\ActiveRecord |
| 19 | { | 19 | { |
| 20 | + | ||
| 21 | + public function getMenuList() | ||
| 22 | + { | ||
| 23 | + return yii::$app->db->createCommand(' | ||
| 24 | + SELECT | ||
| 25 | + `termin_lang`.termin_title, `termin_lang`.termin_id | ||
| 26 | + FROM `menu` | ||
| 27 | + INNER JOIN `termin_lang` ON `termin_lang`.termin_id = `menu`.termin_id | ||
| 28 | + AND `termin_lang`.lang_id = '.yii::$app->lang_id.' | ||
| 29 | + ORDER BY `menu`.menu_pid ASC, `menu`.sortorder ASC | ||
| 30 | + ')->queryAll(); | ||
| 31 | +/* | ||
| 32 | + return $this->find() | ||
| 33 | + ->selectOption('`termin_lang`.termin_title') | ||
| 34 | + ->from('menu') | ||
| 35 | + ->join( | ||
| 36 | + 'INNER JOIN', | ||
| 37 | + '`termin_lang`.termin_id = `menu`.termin_id', | ||
| 38 | + ['lang_id' => yii::$app->lang_id]) | ||
| 39 | + ->all(); | ||
| 40 | +*/ | ||
| 41 | + } | ||
| 42 | + | ||
| 20 | /** | 43 | /** |
| 21 | * @inheritdoc | 44 | * @inheritdoc |
| 22 | */ | 45 | */ |
common/models/Page-i18n.php deleted
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace common\models; | ||
| 4 | - | ||
| 5 | -use Yii; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * This is the model class for table "page". | ||
| 9 | - * | ||
| 10 | - * @property integer $page_id | ||
| 11 | - * @property string $date_add | ||
| 12 | - * @property integer $template_id | ||
| 13 | - * @property integer $image_id | ||
| 14 | - * @property integer $show | ||
| 15 | - */ | ||
| 16 | -class Page extends \yii\db\ActiveRecord | ||
| 17 | -{ | ||
| 18 | - /** | ||
| 19 | - * @inheritdoc | ||
| 20 | - */ | ||
| 21 | - public static function tableName() | ||
| 22 | - { | ||
| 23 | - return 'page'; | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - /** | ||
| 27 | - * @inheritdoc | ||
| 28 | - */ | ||
| 29 | - public function rules() | ||
| 30 | - { | ||
| 31 | - return [ | ||
| 32 | - [['date_add', 'template_id', 'image_id', 'show'], 'required'], | ||
| 33 | - [['date_add'], 'safe'], | ||
| 34 | - [['template_id', 'image_id', 'show'], 'integer'] | ||
| 35 | - ]; | ||
| 36 | - } | ||
| 37 | - | ||
| 38 | - /** | ||
| 39 | - * @inheritdoc | ||
| 40 | - */ | ||
| 41 | - public function attributeLabels() | ||
| 42 | - { | ||
| 43 | - return [ | ||
| 44 | - 'page_id' => Yii::t('app/Lang', 'Page ID'), | ||
| 45 | - 'date_add' => Yii::t('app/Lang', 'Date Add'), | ||
| 46 | - 'template_id' => Yii::t('app/Lang', 'Template ID'), | ||
| 47 | - 'image_id' => Yii::t('app/Lang', 'Image ID'), | ||
| 48 | - 'show' => Yii::t('app/Lang', 'Show'), | ||
| 49 | - ]; | ||
| 50 | - } | ||
| 51 | -} |
common/models/Page.php
| @@ -31,7 +31,7 @@ class Page extends \yii\db\ActiveRecord | @@ -31,7 +31,7 @@ class Page extends \yii\db\ActiveRecord | ||
| 31 | 31 | ||
| 32 | public function getData() | 32 | public function getData() |
| 33 | { | 33 | { |
| 34 | - $this->data = PageLang::find()->where(['page_id' => $this->page_id, 'lang_id' => 1])->one(); | 34 | + $this->data = PageLang::find()->where(['page_id' => $this->page_id, 'lang_id' => yii::$app->lang_id])->one(); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | public function getDataByKey($key) | 37 | public function getDataByKey($key) |
| @@ -45,12 +45,7 @@ class Page extends \yii\db\ActiveRecord | @@ -45,12 +45,7 @@ class Page extends \yii\db\ActiveRecord | ||
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | // ==== DATA PAGE LANG FIELD ==== | 47 | // ==== DATA PAGE LANG FIELD ==== |
| 48 | - | ||
| 49 | - public function getExtraField($key) | ||
| 50 | - { | ||
| 51 | - return PageLang::find()->where(['page_id' => $this->page_id, 'lang_id' => 1])->one()->$key; | ||
| 52 | - } | ||
| 53 | - | 48 | + |
| 54 | public function getTitle() | 49 | public function getTitle() |
| 55 | { | 50 | { |
| 56 | return $this->getDataByKey('title'); | 51 | return $this->getDataByKey('title'); |
frontend/views/layouts/main.php
| @@ -27,6 +27,7 @@ AppAsset::register($this); | @@ -27,6 +27,7 @@ AppAsset::register($this); | ||
| 27 | 27 | ||
| 28 | <div class="wrap"> | 28 | <div class="wrap"> |
| 29 | <?php | 29 | <?php |
| 30 | + | ||
| 30 | NavBar::begin([ | 31 | NavBar::begin([ |
| 31 | 'brandLabel' => 'My Company', | 32 | 'brandLabel' => 'My Company', |
| 32 | 'brandUrl' => Yii::$app->homeUrl, | 33 | 'brandUrl' => Yii::$app->homeUrl, |
| @@ -34,27 +35,44 @@ AppAsset::register($this); | @@ -34,27 +35,44 @@ AppAsset::register($this); | ||
| 34 | 'class' => 'navbar-inverse navbar-fixed-top', | 35 | 'class' => 'navbar-inverse navbar-fixed-top', |
| 35 | ], | 36 | ], |
| 36 | ]); | 37 | ]); |
| 38 | + | ||
| 37 | $menuItems = [ | 39 | $menuItems = [ |
| 38 | ['label' => 'Home', 'url' => ['/site/index']], | 40 | ['label' => 'Home', 'url' => ['/site/index']], |
| 39 | ['label' => 'About', 'url' => ['/site/about']], | 41 | ['label' => 'About', 'url' => ['/site/about']], |
| 40 | ['label' => 'Contact', 'url' => ['/site/contact']], | 42 | ['label' => 'Contact', 'url' => ['/site/contact']], |
| 41 | ]; | 43 | ]; |
| 42 | - if (Yii::$app->user->isGuest) { | 44 | + |
| 45 | + // меню с базы | ||
| 46 | + $menuItems = []; | ||
| 47 | + | ||
| 48 | + foreach ((new \frontend\models\Front())->actionMenu() as $row) | ||
| 49 | + { | ||
| 50 | + $menuItems[] = ['label' => $row['termin_title'], 'url' => $row['termin_id']]; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + if (Yii::$app->user->isGuest) | ||
| 54 | + { | ||
| 43 | $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']]; | 55 | $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']]; |
| 44 | $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; | 56 | $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; |
| 45 | - } else { | 57 | + } |
| 58 | + else | ||
| 59 | + { | ||
| 46 | $menuItems[] = [ | 60 | $menuItems[] = [ |
| 47 | 'label' => 'Logout (' . Yii::$app->user->identity->username . ')', | 61 | 'label' => 'Logout (' . Yii::$app->user->identity->username . ')', |
| 48 | 'url' => ['/site/logout'], | 62 | 'url' => ['/site/logout'], |
| 49 | 'linkOptions' => ['data-method' => 'post'] | 63 | 'linkOptions' => ['data-method' => 'post'] |
| 50 | ]; | 64 | ]; |
| 51 | } | 65 | } |
| 66 | + | ||
| 52 | echo Nav::widget([ | 67 | echo Nav::widget([ |
| 53 | 'options' => ['class' => 'navbar-nav navbar-right'], | 68 | 'options' => ['class' => 'navbar-nav navbar-right'], |
| 54 | 'items' => $menuItems, | 69 | 'items' => $menuItems, |
| 55 | ]); | 70 | ]); |
| 71 | + | ||
| 56 | NavBar::end(); | 72 | NavBar::end(); |
| 73 | + | ||
| 57 | ?> | 74 | ?> |
| 75 | + | ||
| 58 | 76 | ||
| 59 | <div class="container"> | 77 | <div class="container"> |
| 60 | <?= Breadcrumbs::widget([ | 78 | <?= Breadcrumbs::widget([ |