Skip to content

Commit 546d9d0

Browse files
author
Eugene Terentev
authored
Merge pull request #642 from nikosid/master
Small fixes in backend menu and code style correcting
2 parents 11fc1e2 + 824ce27 commit 546d9d0

File tree

9 files changed

+61
-71
lines changed

9 files changed

+61
-71
lines changed

backend/modules/content/controllers/ArticleController.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ public function actionUpdate($id)
7777

7878
if ($article->load(Yii::$app->request->post()) && $article->save()) {
7979
return $this->redirect(['index']);
80-
} else {
81-
return $this->render('update', [
82-
'model' => $article,
83-
'categories' => ArticleCategory::find()->active()->all(),
84-
]);
8580
}
81+
return $this->render('update', [
82+
'model' => $article,
83+
'categories' => ArticleCategory::find()->active()->all(),
84+
]);
8685
}
8786

8887
/**
@@ -107,9 +106,9 @@ protected function findModel($id)
107106
{
108107
if (($model = Article::findOne($id)) !== null) {
109108
return $model;
110-
} else {
111-
throw new NotFoundHttpException('The requested page does not exist.');
112109
}
110+
throw new NotFoundHttpException('The requested page does not exist.');
111+
113112
}
114113

115114
}

backend/modules/content/controllers/CategoryController.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,19 @@ public function actionIndex()
3939

4040
if ($category->load(Yii::$app->request->post()) && $category->save()) {
4141
return $this->redirect(['index']);
42-
} else {
43-
$searchModel = new ArticleCategorySearch();
44-
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
45-
46-
$categories = ArticleCategory::find()->noParents()->all();
47-
$categories = ArrayHelper::map($categories, 'id', 'title');
48-
49-
return $this->render('index', [
50-
'searchModel' => $searchModel,
51-
'dataProvider' => $dataProvider,
52-
'model' => $category,
53-
'categories' => $categories,
54-
]);
5542
}
43+
$searchModel = new ArticleCategorySearch();
44+
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
45+
46+
$categories = ArticleCategory::find()->noParents()->all();
47+
$categories = ArrayHelper::map($categories, 'id', 'title');
48+
49+
return $this->render('index', [
50+
'searchModel' => $searchModel,
51+
'dataProvider' => $dataProvider,
52+
'model' => $category,
53+
'categories' => $categories,
54+
]);
5655
}
5756

5857
/**
@@ -68,15 +67,14 @@ public function actionUpdate($id)
6867

6968
if ($category->load(Yii::$app->request->post()) && $category->save()) {
7069
return $this->redirect(['index']);
71-
} else {
72-
$categories = ArticleCategory::find()->noParents()->andWhere(['not', ['id' => $id]])->all();
73-
$categories = ArrayHelper::map($categories, 'id', 'title');
74-
75-
return $this->render('update', [
76-
'model' => $category,
77-
'categories' => $categories,
78-
]);
7970
}
71+
$categories = ArticleCategory::find()->noParents()->andWhere(['not', ['id' => $id]])->all();
72+
$categories = ArrayHelper::map($categories, 'id', 'title');
73+
74+
return $this->render('update', [
75+
'model' => $category,
76+
'categories' => $categories,
77+
]);
8078
}
8179

8280
/**
@@ -101,8 +99,7 @@ protected function findModel($id)
10199
{
102100
if (($model = ArticleCategory::findOne($id)) !== null) {
103101
return $model;
104-
} else {
105-
throw new NotFoundHttpException('The requested page does not exist.');
106102
}
103+
throw new NotFoundHttpException('The requested page does not exist.');
107104
}
108105
}

backend/modules/content/controllers/PageController.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ public function actionIndex()
3838

3939
if ($page->load(Yii::$app->request->post()) && $page->save()) {
4040
return $this->redirect(['index']);
41-
} else {
42-
$searchModel = new PageSearch();
43-
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
44-
45-
return $this->render('index', [
46-
'searchModel' => $searchModel,
47-
'dataProvider' => $dataProvider,
48-
'model' => $page,
49-
]);
5041
}
42+
$searchModel = new PageSearch();
43+
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
44+
45+
return $this->render('index', [
46+
'searchModel' => $searchModel,
47+
'dataProvider' => $dataProvider,
48+
'model' => $page,
49+
]);
5150
}
5251

5352
/**
@@ -61,11 +60,10 @@ public function actionCreate()
6160

6261
if ($page->load(Yii::$app->request->post()) && $page->save()) {
6362
return $this->redirect(['index']);
64-
} else {
65-
return $this->render('create', [
66-
'model' => $page,
67-
]);
6863
}
64+
return $this->render('create', [
65+
'model' => $page,
66+
]);
6967
}
7068

7169
/**
@@ -110,8 +108,7 @@ protected function findModel($id)
110108
{
111109
if (($model = Page::findOne($id)) !== null) {
112110
return $model;
113-
} else {
114-
throw new NotFoundHttpException('The requested page does not exist.');
115111
}
112+
throw new NotFoundHttpException('The requested page does not exist.');
116113
}
117114
}

backend/modules/content/views/category/update.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
]) . ' ' . $model->title;
1212

1313
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Article Categories'), 'url' => ['index']];
14-
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
1514
$this->params['breadcrumbs'][] = Yii::t('backend', 'Update');
1615

1716
?>

backend/views/_gii/templates/controller.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,10 @@ public function actionCreate()
107107

108108
if ($model->load(Yii::$app->request->post()) && $model->save()) {
109109
return $this->redirect(['view', <?php echo $urlParams ?>]);
110-
} else {
111-
return $this->render('create', [
112-
'model' => $model,
113-
]);
114110
}
111+
return $this->render('create', [
112+
'model' => $model,
113+
]);
115114
}
116115

117116
/**
@@ -126,11 +125,10 @@ public function actionUpdate(<?php echo $actionParams ?>)
126125

127126
if ($model->load(Yii::$app->request->post()) && $model->save()) {
128127
return $this->redirect(['view', <?php echo $urlParams ?>]);
129-
} else {
130-
return $this->render('update', [
131-
'model' => $model,
132-
]);
133128
}
129+
return $this->render('update', [
130+
'model' => $model,
131+
]);
134132
}
135133

136134
/**
@@ -168,8 +166,7 @@ protected function findModel(<?php echo $actionParams ?>)
168166
?>
169167
if (($model = <?php echo $modelClass ?>::findOne(<?php echo $condition ?>)) !== null) {
170168
return $model;
171-
} else {
172-
throw new NotFoundHttpException('The requested page does not exist.');
173169
}
170+
throw new NotFoundHttpException('The requested page does not exist.');
174171
}
175172
}

backend/views/layouts/base.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
$bundle = BackendAsset::register($this);
1010

11-
$this->params['body-class'] = array_key_exists('body-class', $this->params) ?
12-
$this->params['body-class']
13-
: null;
11+
$this->params['body-class'] = $this->params['body-class'] ?? null;
1412
?>
1513

1614
<?php $this->beginPage() ?>
@@ -39,4 +37,4 @@
3937
<?php $this->endBody() ?>
4038
<?php echo Html::endTag('body') ?>
4139
</html>
42-
<?php $this->endPage() ?>
40+
<?php $this->endPage() ?>

backend/views/layouts/clear.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22
/**
33
* @var $this yii\web\View
4+
* @var $content string
45
*/
56
?>
67
<?php $this->beginContent('@backend/views/layouts/common.php'); ?>
78
<?php echo $content ?>
8-
<?php $this->endContent(); ?>
9+
<?php $this->endContent(); ?>

backend/views/layouts/common.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* @var $this yii\web\View
3+
* @var $this yii\web\View
44
* @var $content string
55
*/
66

@@ -154,7 +154,7 @@ class="img-circle"/>
154154
'label' => Yii::t('backend', 'Users'),
155155
'icon' => '<i class="fa fa-users"></i>',
156156
'url' => ['/user/index'],
157-
'active' => (Yii::$app->controller->id == 'user'),
157+
'active' => Yii::$app->controller->id === 'user',
158158
'visible' => Yii::$app->user->can('administrator'),
159159
],
160160
[
@@ -165,26 +165,27 @@ class="img-circle"/>
165165
'label' => Yii::t('backend', 'Static pages'),
166166
'url' => ['/content/page/index'],
167167
'icon' => '<i class="fa fa-thumb-tack"></i>',
168-
'active' => (Yii::$app->controller->id == 'page'),
168+
'active' => Yii::$app->controller->id === 'page',
169169
],
170170
[
171171
'label' => Yii::t('backend', 'Articles'),
172172
'url' => '#',
173173
'icon' => '<i class="fa fa-files-o"></i>',
174174
'options' => ['class' => 'treeview'],
175-
'active' => (Yii::$app->controller->module->id == 'article'),
175+
'active' => 'content' === Yii::$app->controller->module->id &&
176+
('article' === Yii::$app->controller->id || 'category' === Yii::$app->controller->id),
176177
'items' => [
177178
[
178179
'label' => Yii::t('backend', 'Articles'),
179180
'url' => ['/content/article/index'],
180181
'icon' => '<i class="fa fa-file-o"></i>',
181-
'active' => (Yii::$app->controller->id == 'default'),
182+
'active' => Yii::$app->controller->id === 'article',
182183
],
183184
[
184185
'label' => Yii::t('backend', 'Categories'),
185186
'url' => ['/content/category/index'],
186187
'icon' => '<i class="fa fa-folder-open-o"></i>',
187-
'active' => (Yii::$app->controller->id == 'category'),
188+
'active' => Yii::$app->controller->id === 'category',
188189
],
189190
],
190191
],
@@ -193,19 +194,19 @@ class="img-circle"/>
193194
'url' => '#',
194195
'icon' => '<i class="fa fa-code"></i>',
195196
'options' => ['class' => 'treeview'],
196-
'active' => (Yii::$app->controller->module->id == 'widget'),
197+
'active' => Yii::$app->controller->module->id === 'widget',
197198
'items' => [
198199
[
199200
'label' => Yii::t('backend', 'Text Blocks'),
200201
'url' => ['/widget/text/index'],
201202
'icon' => '<i class="fa fa-circle-o"></i>',
202-
'active' => (Yii::$app->controller->id == 'text'),
203+
'active' => Yii::$app->controller->id === 'text',
203204
],
204205
[
205206
'label' => Yii::t('backend', 'Menu'),
206207
'url' => ['/widget/menu/index'],
207208
'icon' => '<i class="fa fa-circle-o"></i>',
208-
'active' => (Yii::$app->controller->id == 'menu'),
209+
'active' => Yii::$app->controller->id === 'menu',
209210
],
210211
[
211212
'label' => Yii::t('backend', 'Carousel'),

backend/views/layouts/main.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @var $this yii\web\View
4+
* @var $content string
45
*/
56
?>
67
<?php $this->beginContent('@backend/views/layouts/common.php'); ?>
@@ -9,4 +10,4 @@
910
<?php echo $content ?>
1011
</div>
1112
</div>
12-
<?php $this->endContent(); ?>
13+
<?php $this->endContent(); ?>

0 commit comments

Comments
 (0)